0
我怎麼能這樣blob
文件上載到我的文件夾ID的谷歌雲端硬盤文件夾:如何使用Javascript將簡單/文本文件上傳到谷歌驅動器?
var blob = new Blob([credentialText], {
type: "text/plain;charset=utf-8;",
});
文檔似乎很不清楚。我已經檢查了這個link,但是沒有我如何提出請求的例子......我也檢查了CORS請求,但沒有幫助。我這樣失去:(
在此先感謝
我想這和它的工作:
var createFile = function(name,text,parentId) {
var auth_token = $rootScope.accessToken;
const boundary = '-------314159265358979323846';
const delimiter = "\r\n--" + boundary + "\r\n";
const close_delim = "\r\n--" + boundary + "--";
var mimeType = 'text/plain';
var metadata = {
"name" : name,
"mimeType": 'text/plain',
"parents": [parentId]
};
var multipartRequestBody =
delimiter + 'Content-Type: application/json\r\n\r\n' +
JSON.stringify(metadata) +
delimiter + 'Content-Type: application/json\r\n\r\n' +
text +
close_delim;
gapi.client.request({
'path': '/upload/drive/v3/files/',
'method': 'POST',
'params': {'uploadType': 'multipart'},
'headers': { 'Content-Type': 'multipart/form-data; boundary="' + boundary + '"', 'Authorization': 'Bearer ' + auth_token, },
'body': multipartRequestBody
}).execute(function(file) {
console.log(file);
console.log("Wrote to file " + file.name + " id: " + file.id);
}, function(error){
console.log(error);
});
}