javascript - google drive api Resumable upload error 400 Parse Error?
问题描述
“分段上传”是正常的,但“可恢复上传”不是。
我的“代码”有什么问题?
用户网络中断时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);
});
}
解决方案
推荐阅读
- python - 根据列的小时范围创建新的 DataFrame
- javascript - 如何不从 JavaScript 中的对象返回字段?
- node.js - 更改代码时避免重新启动 docker
- python - 对于 youtube-dl,Python 正在查看字符而不是数组中的完整字符串/元素
- python - 如何使用python将iBeacon RSSI值存储到数组中一分钟
- python - 如何在设置 django 中找到主机名和端口,以便在电子邮件中显示图像的完整路径?
- laravel - Laravel 多表身份验证
- openshift - openshift_set_node_ip 在 openshift 3.11 中已弃用,应该改用什么?
- python - 无限循环中的keras生成器
- python - 如何使用 Python 从网站上下载多个 CSV 文件?