Skip to content

Commit

Permalink
luci-app-filemanager: Use the read_direct method to download the file
Browse files Browse the repository at this point in the history
Signed-off-by: Dmitry R <[email protected]>
  • Loading branch information
rdmitry0911 committed Dec 24, 2024
1 parent 7cb2f65 commit 5f8a0e3
Showing 1 changed file with 16 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1998,25 +1998,23 @@ return view.extend({
// Download the file to the user's local machine
var self = this;
var fileName = filePath.split('/').pop();
fs.read(filePath, {
binary: true
}).then(function(content) {
var blob = new Blob([content], {
type: 'application/octet-stream'
// Use the read_direct method to download the file
fs.read_direct(filePath, 'blob')
.then(function(blob) {
if (!(blob instanceof Blob)) {
throw new Error(_('Response is not a Blob'));
}
var url = window.URL.createObjectURL(blob);
var a = document.createElement('a');
a.href = url;
a.download = fileName;
document.body.appendChild(a);
a.click();
a.remove();
window.URL.revokeObjectURL(url);
}).catch(function(err) {
pop(null, E('p', _('Failed to download file "%s": %s').format(fileName, err.message)), 'error');
});
var downloadLink = document.createElement('a');
downloadLink.href = URL.createObjectURL(blob);
downloadLink.download = fileName;
document.body.appendChild(downloadLink);
downloadLink.click();
document.body.removeChild(downloadLink);
var statusInfo = document.getElementById('status-info');
if (statusInfo) {
statusInfo.textContent = _('Downloaded file: "%s".').format(fileName);
}
}).catch(function(err) {
pop(null, E('p', _('Failed to download file "%s": %s').format(fileName, err.message)), 'error');
});
},

// Handler for deleting a file
Expand Down

0 comments on commit 5f8a0e3

Please sign in to comment.