1

I am trying to consume Google Picker API from SAP UI5 application. I need to read the file content as BLOB and convert to Base64 string. I have reached till getting the URL for the file from the response of Google Picker API. However, further to read the BLOB which I can then use to convert it to Base64 string, I need directions. Kindly advise.

Google Picker API documentation referred

The below code helps in getting the metadata of the file:

function pickerCallback(data) {
        var url = 'nothing';
        if (data[google.picker.Response.ACTION] == google.picker.Action.PICKED) {
          var doc = data[google.picker.Response.DOCUMENTS][0];
          url = doc[google.picker.Document.URL];
        }
        var message = 'You picked: ' + url;
        document.getElementById('result').innerHTML = message;
      }

This helps in obtaining metadata. However I need to read the content of the file. Either as BLOB content or Base64 string.

Samad.

Jaro
  • 1,757
  • 1
  • 15
  • 36
  • Hi, you can look at link below: https://stackoverflow.com/questions/18650168/convert-blob-to-base64. also, can you provide more details as to what you are trying to achieve – jasbir Oct 08 '18 at 13:07
  • Hi Jasbir I need to get the content of the selected file in Binary format. I need to later convert the content into a Base64 string to be used for another API input. – Abdul Samad Oct 09 '18 at 10:45
  • So which sapui5 control you using to upload files? I can help you with getting content. Another thing if you are not using any up[laod control, are you trying to read content via odata read call? – jasbir Oct 10 '18 at 08:45
  • Hi @jasbir : Currently I have used files.get and simulated in POSTMAN to check if its working. I think this should be ok, will try out in the system and if there are any hiccups, I will get back. Thanks for supporting me. – Abdul Samad Oct 11 '18 at 09:33

1 Answers1

0

Assuming a Google Drive file is being picked, you could use the Google Drive REST API. Specifically, you could use Files: get to download a file, and then process it further. If it is a Google Doc, you would use Files: export to convert it first.

Also see https://developers.google.com/drive/api/v3/manage-downloads

rikusv
  • 646
  • 5
  • 10
  • Thanks for the reply Rikusv. From data[google.picker.Response.DOCUMENTS][0], am able to get the metadata of the document, however I need to get the content as binary data. With files.get, will I be able to get the content as BLOB. – Abdul Samad Oct 09 '18 at 10:42
  • Yes, using `alt=media`. See https://developers.google.com/drive/api/v3/manage-downloads – rikusv Oct 09 '18 at 10:57
  • Thanks @rikusv. I would like to know if there is any pricing for Google Picker API or the other Files related methods as I couldn't see information under https://developers.google.com/picker/docs/. – Abdul Samad Oct 19 '18 at 09:40
  • As far as I know it is free. – rikusv Oct 19 '18 at 09:50