如果我想下载一个文件,我应该在下面的 then
块中做什么?
If I want to download a file, what should I do in the then
block below?
function downloadFile(token, fileId) {
let url = `https://www.googleapis.com/drive/v2/files/${fileId}?alt=media`;
return fetch(url, {
method: 'GET',
headers: {
'Authorization': token
}
}).then(...);
}
注意代码在客户端.
我暂时用download.js解决了这个问题 和 blob
.
let download = require('./download.min');
...
function downloadFile(token, fileId) {
let url = `https://www.googleapis.com/drive/v2/files/${fileId}?alt=media`;
return fetch(url, {
method: 'GET',
headers: {
'Authorization': token
}
}).then(function(resp) {
return resp.blob();
}).then(function(blob) {
download(blob);
});
}
它适用于小文件,但可能不适用于大文件.我想我应该更多地挖掘 Stream.
It's working for small files, but maybe not working for large files. I think I should dig Stream more.
这篇关于如何使用 window.fetch 下载文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!