Do you have an example of loading google boot disk from javascript? I read the instructions at: https://developers.google.com/drive/manage-uploads#resumable And I tried to make sure to resume such a download:
var metadata = { 'Content-Length': '200', 'title': "MyFileTitle" }; var multipartRequestBody = JSON.stringify(metadata); var request = gapi.client.request({ 'path': '/upload/drive/v2/files', 'method': 'POST', 'params': {'uploadType': 'resumable'}, 'headers': { 'Authorization': 'Bearer ' + acToken, 'Content-Type': 'application/json; charset=UTF-8', 'X-Upload-Content-Type': 'application/vnd.google- apps.document' }, 'body': multipartRequestBody}); callback = function(ret, raw) { var obj = $.parseJSON(raw); var uploadUrl = obj.gapiRequest["data"]["headers"]["location"]; }; request.execute(callback);
This request was successful and I am getting a download URL. But when I try to download the content using this url:
const boundary = '-------314159265358979323846'; const delimiter = "\r\n--" + boundary + "\r\n"; const close_delim = "\r\n--" + boundary + "--"; var contentType = 'text/html'; var metadata = { 'title': 'MyFileTitle', 'mimeType': contentType }; var base64Data = btoa(fileToUpload); var multipartRequestBody = delimiter + 'Content-Type: application/json\r\n\r\n' + JSON.stringify(metadata) + delimiter + 'Content-Type: ' + contentType + '\r\n' + 'Content-Transfer-Encoding: base64\r\n' + '\r\n' + base64Data + close_delim; var request = gapi.client.request({ 'path': uploadUrl.replace('https://www.googleapis.com', ''), 'method': 'PUT', 'params': {'uploadType': 'multipart', 'convert': 'true', 'Content-Length': fileToUpload.length}, 'headers': { 'Authorization': 'Bearer ' + acToken, 'Content-Type': 'multipart/mixed; boundary="' + boundary + '"' }, 'body': multipartRequestBody}); callback = function(file) { console.log(file) }; request.execute(callback);
The request returns an error (status 400 Bad request).
Can someone give me an example of a valid Drive API request to resume loading using Javascript?
source share