Uploaded Gmail Attachment To Google Drive (with mimeType?)

Hi all. I’d like to know how to get an attachment from a Gmail email message. My current flow tries using a custom Gmail API call to GET it and the data is returned as a base64 string in the body.data element.

Next I do a hack-y check if it’s a PDF by checking if the base64 string starts with “JVBERi0” which decodes to “%PDF-”.

Now I’m at the point of trying to upload the attachment to Google Drive. In the Upload file piece, the File input helper text states “The file URL or base64 to upload”. So I passed in the base64 string. This doesn’t work and I get the error:

{
  "file": [
    "Expected file url or base64 with mimeType, but found value: JVBERi0..."
  ]
}

I’ve tried to pass in the mimeType along with it without success. Can anyone help me to get the file to upload? In any way at all, I’m not fixated on my strategy.

Here’ my current flow for reference:

Hello @captainkrumm ,

Since you are using a custom API to get attachments, how do you obtain the message ID? If you are using Gmail as the trigger, it has an attachments field that can be used directly in the Google Drive step.

I will run this flow monthly and calculate the time ago using a Code piece. I use this value in a custom API call to get all emails received in that period (one month, in my flow). This returns the emails’ message IDs.

I would really appreciate an answer to this still!

I’m disappointed with the lack of help in this community. It seems you almost always end up finding the answer yourself after days or weeks in my case.

So I’ll tell you the solution! You prepend data:application/pdf;base64, to the base64 string. It’s explained in this post: How to change image to pdf - #2 by GunnerJnr

1 Like

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Hi @captainkrumm

Interesting, I am thinking what would be the best case scenario?

  • We can upload the file without name or extension, (maybe we can guess from content not sure if that possible)?
  • Suggest the solution in error message

Linking this issue for reference:

1 Like

Now it returns with mimetype as well