From ae1d32454d00d73afcf48adf89c0069503a0dde3 Mon Sep 17 00:00:00 2001 From: benweet Date: Sun, 24 Mar 2013 19:08:31 +0000 Subject: [PATCH] Google Drive support --- index.html | 28 +++------------------------- js/main.js | 1 + 2 files changed, 4 insertions(+), 25 deletions(-) diff --git a/index.html b/index.html index 640c232e..6767863a 100644 --- a/index.html +++ b/index.html @@ -67,40 +67,18 @@ * @param {Function} callback Function to call when the request is complete. */ function insertFile(fileData, callback) { - const - boundary = '-------314159265358979323846'; - const - delimiter = "\r\n--" + boundary + "\r\n"; - const - close_delim = "\r\n--" + boundary + "--"; - - var reader = new FileReader(); - reader.readAsBinaryString(fileData); - reader.onload = function(e) { - var contentType = fileData.type || 'application/octet-stream'; - var metadata = { 'title' : fileData.name, 'mimeType' : contentType }; - - var base64Data = btoa(reader.result); - 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 }); + 'params' : { 'uploadType' : 'media' }, + 'headers' : { 'Content-Type' : 'text/plain' }, + 'body' : fileData }); if (!callback) { callback = function(file) { console.log(file) }; } request.execute(callback); - } }