Inserting HTML content with base64-encoded images into Google Docs

Hey everyone,

I’m working on a project where I need to add HTML content to Google Docs using their API. I’m coding in Objective-C. The tricky part is that I’m trying to include images that are base64 encoded.

Here’s what I’ve done so far:

  1. I’m using the text/html MIME type for the upload.
  2. My img tags look like this: <img src='data:image/jpeg;base64,encodedImageData' />
  3. I’ve double-checked that the encoding is correct. I can decode it back to the original image without issues.

The good news is that the upload works, and all the text formatting (fonts, colors, etc.) shows up correctly in the Google Doc. The bad problem? The images aren’t displaying at all.

Has anyone run into this before? Is it a limitation on Google’s end, or am I missing something obvious?

Thanks for any help!

google docs images are tricky sometimes. i solved it by uploading pics to google drive and linking them in the doc via the drive api. a bit extra work, but it works.

I’ve actually encountered this issue before when working on a similar project. From my experience, Google Docs doesn’t support base64-encoded images directly in HTML content. It’s a limitation on their end, unfortunately.

What worked for me was to convert the base64-encoded images to actual image files first, then upload them separately to Google Drive. After that, I used the file IDs from Google Drive to reference the images in my HTML content.

The process was a bit more complex, but it gave me the desired result. You’ll need to use the Google Drive API alongside the Docs API. First, upload each image to Drive, get its ID, then use something like <img src='https://drive.google.com/uc?id=YOUR_FILE_ID' /> in your HTML.

It’s not as straightforward as directly embedding base64 data, but it’s a reliable workaround for this limitation. Hope this helps!

In a recent project I faced a similar challenge where the base64-encoded images would not display in Google Docs. I discovered that the API does not support embedding images directly from base64 data. Instead, I resorted to uploading the images to Google Drive and then using the obtained file IDs to create valid image URLs. This alternative approach, although it introduces extra steps and necessitates managing appropriate permissions with the Drive API, reliably ensured that the images displayed correctly in the document.