Skip to content

Instantly share code, notes, and snippets.

@cowsrule
Created April 7, 2017 10:15
Show Gist options
  • Save cowsrule/0e41eba2e31e0fc4a91141fafcaab1b9 to your computer and use it in GitHub Desktop.
Save cowsrule/0e41eba2e31e0fc4a91141fafcaab1b9 to your computer and use it in GitHub Desktop.
var reader = new FileReader();
reader.readAsBinaryString(fileData);
reader.onload = function (e)
{
var contentType = fileData.type || MimeTypes.Unknown;
var runUpload = function (folderID)
{
var metadata =
{
'title': fileData.name,
'mimeType': contentType,
'parents': [ { 'id': defaultParent } ]
};
var base64Data = btoa(reader.result);
var body = 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': '/upload/drive/v2/files',
'method': 'POST',
'params': { 'uploadType': 'multipart' },
'headers': {
'Content-Type': 'multipart/mixed; boundary="' + boundary + '"'
},
'body': body
});
var callback = function (file)
{
};
request.execute(callback);
}.bind(this);
runUpload();
}.bind(this);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment