Google Drive in Retool - Creating Image File

Hi all,

Please forgive the basic question, I've tried to work this issue with the following article (Using Google Drive in Retool: Configuring OAuth, Viewing & Creating New Files), but can't seem to crack the solution.

As the article suggests, I'm using two staged approach, but I'm attempting to adapt for an image instead of text in that case.

  1. First query to update metadata (mimeType: images/jpeg)
  2. Second query to upload the image data (base64Data) from a separate API request.

In the second query, i've structured it as a PATCH where uploadType = media and body is {{static_image.data}} which is the response from the API request.

I'd be extremely appreciative if anyone has thoughts on what I might be doing wrong here.



1 Like

@JoeyKarczewski, any thoughts on this? :face_with_monocle:

What do you get? Do you get any error or some other outcome? Do you get no file even though authentication is successful?

I am also having some difficulties. I was getting no results and then suddenly it started making files. Seemed like there was a lag to the authentication or something.

According to the Google Drive API https://developers.google.com/drive/api/guides/manage-uploads#resumable
the second query should use PUT (not PATCH or POST). I don't particularly know the difference.

I get a file but it always a text file. I am trying to save the Base64Data (just you have above), that comes from a fileDropZone component.

I wondered if I should be choosing a different format other than RAW?

Any clues?

I solved it!

I needed to use binary format!

Jeremy

Here are my queries...

PutFileFirst query...


Filename and filesize are passed as additionalScope variables.

PutFileSecond query...

Interesting! Couple of questions for you -

  1. Is filetype = "image/jpeg"?
  2. Is Content-Length = number of bytes from your file?
  3. In your put request, what is your upload_id referencing? Isn't clear how that translates...

Hopeful you've cracked it, and thank you!

it seems to work for both jpg and pdf files (but not for png). The filetype comes from the fileDropzone data, but yes, for this file it's "image/jpeg". And Content-Length is taken from the sizeBytes property of that too.

The upload_id is generated by the first query, "PutFilesFirst", hence PutFilesFirst.metadata.headers...

This is (sort of) described in the Google API documentation (but in my view, quite badly).

https://developers.google.com/drive/api/guides/manage-uploads#uploading

I am yet to implement any resuming an interupted upload procedures.

I hope this helps, happy to answer any other questions if I can. (I'm making it up as I go).

1 Like