Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function insertFile(fileData, callback) {
- const boundary = '-------314159265358979323846';
- const delimiter = "rn--" + boundary + "rn";
- const close_delim = "rn--" + boundary + "--";
- var reader = new FileReader();
- reader.readAsBinaryString(fileData);
- reader.onload = function(e) {
- var contentType = fileData.type || 'application/octet-stream';
- var metadata = {
- 'title': fileData.fileName,
- 'mimeType': contentType
- };
- var base64Data = btoa(reader.result);
- var multipartRequestBody =
- delimiter +
- 'Content-Type: application/jsonrnrn' +
- JSON.stringify(metadata) +
- delimiter +
- 'Content-Type: ' + contentType + 'rn' +
- 'Content-Transfer-Encoding: base64rn' +
- 'rn' +
- base64Data +
- close_delim;
- var request = gapi.client.request({
- 'path': '/upload/drive/v2/files',
- 'method': 'POST',
- 'params': {'uploadType': 'multipart'},
- 'headers': {
- 'Content-Type': 'multipart/mixed; boundary="' + boundary + '"'
- },
- 'body': multipartRequestBody});
- if (!callback) {
- callback = function(file) {
- console.log(file)
- };
- }
- request.execute(callback);
- }
- }
Add Comment
Please, Sign In to add comment