From ffc7d113718ba2cbaf482be5c6ee32c33a671267 Mon Sep 17 00:00:00 2001 From: fenn-cs Date: Thu, 25 May 2023 21:09:47 +0100 Subject: [PATCH] Download files via post request Currently, download requests are handled via a get request which can break in various ways. For example, if the GET URL is too long and the servers MAX_URL_LENGTH (size) is reached a 404 is thrown as reported in #7935 Resolves: https://github.com/nextcloud/server/issues/7935 Signed-off-by: fenn-cs --- apps/files/js/filelist.js | 2 +- apps/files/js/files.js | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/apps/files/js/filelist.js b/apps/files/js/filelist.js index 442fdec93229b..39f448ab35047 100644 --- a/apps/files/js/filelist.js +++ b/apps/files/js/filelist.js @@ -1051,7 +1051,7 @@ }; if(this.getSelectedFiles().length > 1) { - OCA.Files.Files.handleDownload(this.getDownloadUrl(files, dir, true), disableLoadingState); + OCA.Files.Files.handleDownload(this.getDownloadUrl(files, dir, true), disableLoadingState, files, dir); } else { var first = this.getSelectedFiles()[0]; diff --git a/apps/files/js/files.js b/apps/files/js/files.js index b0c3824818309..2dc2f4382d5f6 100644 --- a/apps/files/js/files.js +++ b/apps/files/js/files.js @@ -364,7 +364,7 @@ * @param {string} url download URL * @param {Function} callback function to call once the download has started */ - handleDownload: function(url, callback) { + handleDownload: function(url, callback, files = null, dir = null) { var randomToken = Math.random().toString(36).substring(2), checkForDownloadCookie = function() { if (!OC.Util.isCookieSetToValue('ocDownloadStarted', randomToken)){ @@ -380,6 +380,10 @@ } else { url += '?'; } + filesClient = OC.Files.getClient(); + filesClient = filesClient.getClient(); + // Method signature : request: function (method, url, headers, body, responseType, options) + filesClient.request('POST', url, [], []); OC.redirect(url + 'downloadStartSecret=' + randomToken); OC.Util.waitFor(checkForDownloadCookie, 500); }