Google Drive support
This commit is contained in:
parent
8337af3e7c
commit
06df97c9ff
26
index.html
26
index.html
@ -67,33 +67,12 @@
|
|||||||
* @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(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({
|
var request = gapi.client.request({
|
||||||
'path' : '/upload/drive/v2/files',
|
'path' : '/upload/drive/v2/files',
|
||||||
'method' : 'POST',
|
'method' : 'POST',
|
||||||
'params' : { 'uploadType' : 'multipart' },
|
'params' : { 'uploadType' : 'multipart' },
|
||||||
'headers' : { 'Content-Type' : 'multipart/mixed; boundary="'
|
'headers' : { 'Content-Type' : 'text/plain' },
|
||||||
+ boundary + '"' }, 'body' : multipartRequestBody });
|
'body' : fileData });
|
||||||
if (!callback) {
|
if (!callback) {
|
||||||
callback = function(file) {
|
callback = function(file) {
|
||||||
console.log(file)
|
console.log(file)
|
||||||
@ -101,7 +80,6 @@
|
|||||||
}
|
}
|
||||||
request.execute(callback);
|
request.execute(callback);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
</script>
|
</script>
|
||||||
<script type="text/javascript"
|
<script type="text/javascript"
|
||||||
src="https://apis.google.com/js/client.js?onload=handleClientLoad"></script>
|
src="https://apis.google.com/js/client.js?onload=handleClientLoad"></script>
|
||||||
|
@ -49,6 +49,7 @@
|
|||||||
this.fileSystem[this.currentFile] = this.content;
|
this.fileSystem[this.currentFile] = this.content;
|
||||||
localStorage.fileSystem = JSON.stringify(this.fileSystem);
|
localStorage.fileSystem = JSON.stringify(this.fileSystem);
|
||||||
localStorage.currentFile = this.currentFile;
|
localStorage.currentFile = this.currentFile;
|
||||||
|
insertFile(this.content);
|
||||||
};
|
};
|
||||||
|
|
||||||
function resize() {
|
function resize() {
|
||||||
|
Loading…
Reference in New Issue
Block a user