Google Drive support

This commit is contained in:
benweet 2013-03-24 19:42:15 +00:00
parent 9470d0f2b0
commit f343b1ca78

View File

@ -70,20 +70,38 @@
* @param {File} fileData File object to read data from. * @param {File} fileData File object to read data from.
* @param {Function} callback Function to call when the request is complete. * @param {Function} callback Function to call when the request is complete.
*/ */
function insertFile(fileData, callback) { function insertFile(title, content, callback) {
if(driveUpload) { if(driveUpload) {
var request = gapi.client.request({ const
'path' : '/upload/drive/v2/files', boundary = '-------314159265358979323846';
'method' : 'POST', const
'params' : { 'uploadType' : 'media' }, delimiter = "\r\n--" + boundary + "\r\n";
'headers' : { 'Content-Type' : 'text/plain' }, const
'body' : fileData }); close_delim = "\r\n--" + boundary + "--";
if (!callback) {
callback = function(file) { var contentType = 'text/x-markdown';
console.log(file) var metadata = { 'title' : title, 'mimeType' : contentType };
};
} var base64Data = btoa(content);
request.execute(callback); 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' : '/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);
} }
} }
</script> </script>