“分段上传”是正常的,但“断续上传”不是。
我的“代码”有什么问题?
当用户网络中断时,api是否需要重新传输文件?
文件会从中断中重新传输吗?
对不起,我的英语不好
function uploadPostBlob(selectedFile) {
//selectFile is File Object
var metadata = {
'name': selectedFile.name, // Filename at Google Drive
'mimeType': selectedFile.mimeType, // mimeType at Google Drive
'parents': ['root'], // Folder ID at Google Drive
};
var accessToken = gapi.auth.getToken().access_token; // Here gapi is used for retrieving the access token.
var form = new FormData();
form.append('metadata', new Blob([JSON.stringify(metadata)], {
type: 'application/json'
}));
form.append('file', selectedFile);
//https://www.googleapis.com/upload/drive/v3/files?uploadType=resumable
//https://www.googleapis.com/upload/drive/v3/files?uploadType=multipart
fetch('https://www.googleapis.com/upload/drive/v3/files?uploadType=resumable', {
method: 'POST',
headers: new Headers({
'Authorization': 'Bearer ' + accessToken,
'Content-Type':'application/json; charset=UTF-8'
}),
body: form,
}).then((res) => {
return res.json();
}).then(function(val) {
console.log(val);
});
}