Skip to content

Commit

Permalink
Download files via post request
Browse files Browse the repository at this point in the history
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: #7935

Signed-off-by: fenn-cs <fenn25.fn@gmail.com>
  • Loading branch information
Fenn-CS committed May 25, 2023
1 parent 115689f commit ffc7d11
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
2 changes: 1 addition & 1 deletion apps/files/js/filelist.js
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down
6 changes: 5 additions & 1 deletion apps/files/js/files.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)){
Expand All @@ -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);
}
Expand Down

0 comments on commit ffc7d11

Please sign in to comment.