daily pastebin goal
33%
SHARE
TWEET

Untitled

a guest Jun 14th, 2018 61 Never
Upgrade to PRO!
ENDING IN00days00hours00mins00secs
 
  1. function insertFile(fileData, callback) {
  2.     const boundary = '-------314159265358979323846';
  3.     const delimiter = "rn--" + boundary + "rn";
  4.     const close_delim = "rn--" + boundary + "--";
  5.  
  6.    var reader = new FileReader();
  7.    reader.readAsBinaryString(fileData);
  8.    reader.onload = function(e) {
  9.    var contentType = fileData.type || 'application/octet-stream';
  10.    var metadata = {
  11.   'title': fileData.fileName,
  12.   'mimeType': contentType
  13. };
  14.  
  15. var base64Data = btoa(reader.result);
  16. var multipartRequestBody =
  17.     delimiter +
  18.     'Content-Type: application/jsonrnrn' +
  19.     JSON.stringify(metadata) +
  20.     delimiter +
  21.     'Content-Type: ' + contentType + 'rn' +
  22.     'Content-Transfer-Encoding: base64rn' +
  23.     'rn' +
  24.     base64Data +
  25.     close_delim;
  26.  
  27. var request = gapi.client.request({
  28.     'path': '/upload/drive/v2/files',
  29.     'method': 'POST',
  30.     'params': {'uploadType': 'multipart'},
  31.     'headers': {
  32.       'Content-Type': 'multipart/mixed; boundary="' + boundary + '"'
  33.     },
  34.     'body': multipartRequestBody});
  35. if (!callback) {
  36.   callback = function(file) {
  37.     console.log(file)
  38.   };
  39. }
  40. request.execute(callback);
  41.   }
  42. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top