Upload the file to Google Drive using a telephony api

Correct me if I am wrong, but according to the frequently asked questions that I went through, I read that the javascript client library is used https://developers.google.com/api-client-library/javascript/reference/referencedocs only web applications. I am making a mobile application using a handset in which the user must be able to upload a picture to Google. I look at these links: https://developers.google.com/drive/v2/reference/files/insert

As you can see, it uses the javascript client library to download the file. Is there a way I can do this without using this library. If so, how can I use pure js or jquery?

thanks


Thanks JunYoung ... I was able to finish the part in which you are logged in and log in. Now I am trying to upload a file to my disk. All the examples that I see use the JS client library. https://developers.google.com/drive/quickstart-js I want to accomplish the same thing, but without using gapi.client.request. I want to use a simple POST. Here is my code

const boundary = '-------314159265358979323846'; const delimiter = "\r\n--" + boundary + "\r\n"; const close_delim = "\r\n--" + boundary + "--"; var reader = new FileReader(); var fileContent = this.$.fileInput.getFiles()[0]; reader.readAsBinaryString(fileContent); reader.onload = function(e) { var contentType = fileContent.type || 'application/octet-stream'; var metadata = { 'title': fileContent.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 driveAjax = new enyo.Ajax({ url: 'https://www.googleapis.com/upload/drive/v2/files', method: 'POST', contentType: 'multipart/mixed; boundary="' + boundary + '"', postBody: multipartRequestBody }); driveAjax.response(this, "uploadSuccess"); driveAjax.error(this, "processError"); driveAjax.go({ uploadType:'multipart' }); 

As you can see, I replaced the gapi.client.request component with a simple ajax call. But this does not seem to work. BTW I am using enyo js framework. Can you identify any problems with this?

+4
source share
1 answer

Was there a problem integrating Drive API with Phonegap?

The Drive API is basically HTTP requests, and all of this can be done with pure Javascript. Therefore, you can use jQuery AJAX calls to Files.insert (). However, I would recommend you use the Javascript client. The following is an example of OAuth using the JS client library . Try this example using the Phonegap application and ask the question again if you encounter problems.

+2
source

Source: https://habr.com/ru/post/1488826/


All Articles