xhr download as octet-stream
This commit is contained in:
parent
a1d0eef8a5
commit
e9405f49ee
|
@ -33,7 +33,6 @@ async function download() {
|
||||||
window.addEventListener('unload', unloadHandler);
|
window.addEventListener('unload', unloadHandler);
|
||||||
|
|
||||||
fileReceiver.on('progress', data => {
|
fileReceiver.on('progress', data => {
|
||||||
console.log(`${data[0]}/${data[1]}`);
|
|
||||||
progress.setProgress({ complete: data[0], total: data[1] });
|
progress.setProgress({ complete: data[0], total: data[1] });
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -38,14 +38,13 @@ export default class FileReceiver extends EventEmitter {
|
||||||
}
|
}
|
||||||
|
|
||||||
const blob = new Blob([this.response]);
|
const blob = new Blob([this.response]);
|
||||||
const type = xhr.getResponseHeader('Content-Type');
|
|
||||||
const meta = JSON.parse(xhr.getResponseHeader('X-File-Metadata'));
|
const meta = JSON.parse(xhr.getResponseHeader('X-File-Metadata'));
|
||||||
const fileReader = new FileReader();
|
const fileReader = new FileReader();
|
||||||
fileReader.onload = function() {
|
fileReader.onload = function() {
|
||||||
resolve({
|
resolve({
|
||||||
data: this.result,
|
data: this.result,
|
||||||
name: meta.filename,
|
name: meta.filename,
|
||||||
type,
|
type: meta.mimeType,
|
||||||
iv: meta.id
|
iv: meta.id
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
|
@ -194,7 +194,7 @@ app.get('/assets/download/:id', async (req, res) => {
|
||||||
const contentLength = await storage.length(id);
|
const contentLength = await storage.length(id);
|
||||||
res.writeHead(200, {
|
res.writeHead(200, {
|
||||||
'Content-Disposition': `attachment; filename=${meta.filename}`,
|
'Content-Disposition': `attachment; filename=${meta.filename}`,
|
||||||
'Content-Type': meta.mimeType,
|
'Content-Type': 'application/octet-stream',
|
||||||
'Content-Length': contentLength,
|
'Content-Length': contentLength,
|
||||||
'X-File-Metadata': JSON.stringify(meta)
|
'X-File-Metadata': JSON.stringify(meta)
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue