4

I want to create a new slides out of the local images using Python. Unfortunately, I do not see an example to upload a local image, only an image URL via the official documentation.

That's why I'm wondering is it possible to do that at all? If it is I would appreciate any kind of help.

Thank you very much

Grokify
  • 15,092
  • 6
  • 60
  • 81
Steve S
  • 41
  • 3
  • It seems that the official document shows how to add an image by uploading the image to Google Drive. In your question, do you want to directly load the image of the local PC by downloading from the Slides without uploading the image file? – Tanaike Mar 18 '19 at 23:22
  • Thanks for taking time to respond. I want to load images directly from my local PC to Slides. Can you please share that example that shows how to add image by uploading it to Google Drive? I may consider that option too. Thanks – Steve S Mar 18 '19 at 23:34
  • You can see the sample script at the official document in your question. Is that useful for you? – Tanaike Mar 18 '19 at 23:35
  • Now I feel really stupid but I just can't see it :( – Steve S Mar 19 '19 at 12:20
  • I couldn't understand your reply and your situation. You cannot open the URL of [https://developers.google.com/slides/how-tos/add-image](https://developers.google.com/slides/how-tos/add-image)? Is my understanding correct? – Tanaike Mar 19 '19 at 22:14

2 Answers2

3

From the official documentation:

https://developers.google.com/slides/how-tos/add-image

If you want to add private or local images to a slide, you'll first need to make them available on a publicly accessible URL. One option is to upload your images to Google Cloud Storage and use signed URLs with a 15 minute TTL. Uploaded images are automatically deleted after 15 minutes.

Grokify
  • 15,092
  • 6
  • 60
  • 81
1

Google requires a publicly accessible URL as mentioned in the docs.

You can either:

  1. upload your file to an Internet-accessible server, or
  2. allow the Internet to access your local system.

I'll describe the 2nd approach a bit because the 1st approach is fairly straight-forward.

To allow Google to access your local file without uploading the file to a server, you can use a local HTTP server and expose it to the Internet using a TCP tunneling service like ngrok:

https://ngrok.com/

You can use any local server. If you don't have one, http-server on NPM is easy to use:

https://www.npmjs.com/package/http-server

I've used the ngrok approach successfully.

Grokify
  • 15,092
  • 6
  • 60
  • 81
  • This looks like a great option, thanks! Do you know anything about whether or not something like this is secure without ngrok? That is, I don't want to expose the images being used in the Google Doc template. – Relative0 Nov 12 '22 at 08:33
  • If you want to upload your files to a publicly accessible URL, one way to protect them is to identify the IP/host from which Google is retrieving them and add that as request filter, rejecting requests from other IP/hosts. – Grokify Nov 13 '22 at 11:46