-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Add an image to a google slide? #285
-
Is their an API for adding images to google slides? From local or google drive?
Beta Was this translation helpful? Give feedback.
All reactions
Replies: 2 comments 4 replies
-
gws schema slides.CreateImageRequest but wants to use a public url
Beta Was this translation helpful? Give feedback.
All reactions
-
Yeah this is a limitation of the API. It might work with a base64 data URI.
Beta Was this translation helpful? Give feedback.
All reactions
-
👍 1
-
Was worth a shot
I tried using a base64 data:image/svg+xml;base64,... URI for the createImage request, but unfortunately, the Google Slides API rejected it with the
following error:
1 {
2 "error": {
3 "code": 400,
4 "message": "Invalid requests[0].createImage: The URL is invalid.",
5 "reason": "unknown"
6 }
7 }
This confirms that the Slides API strictly requires a valid, publicly accessible http or https URL and doesn't support embedding images directly via
base64 data URIs.
Beta Was this translation helpful? Give feedback.
All reactions
-
I'll need to know more about the source location to help further. Is it in drive? I think slides makes a copy of the image so there are some tricks from the urls that are available from other Workspace apps using short-term urls with tokens in them.
Beta Was this translation helpful? Give feedback.
All reactions
-
No was a local file. I thought that would be easier to test before trying a Google Drive file.
I just saved https://upload.wikimedia.org/wikipedia/commons/2/2f/Google_2015_logo.svg to my local machine.
I'm pretending this one isn't Public by saving it to my local machine
Beta Was this translation helpful? Give feedback.
All reactions
-
Yeah, there's a way to do this - it's in the Slides API, but it's not super obvious from the CLI docs. You want the slides.CreateImageRequest method. For local files, you need to upload them to Drive first via the Drive API, then reference the Drive file ID in the image request. For public URLs, you can skip the upload and just pass the URL directly in the imageProperties.contentUrl field. I ran into this last year when automating slide generation - the trick is that the CLI doesn't expose a "from local file" shortcut, so you have to stage it in Drive first. Something like: upload with gdrive upload --name foo.png, grab the ID, then call gws slides create-image --object-id=... --image-id=... --url="https://drive.google.com/uc?id=FILE_ID". If you're doing this often, wrap it in a script. Public URLs are easier - just use the direct link in the image request. Not certain if the CLI
Beta Was this translation helpful? Give feedback.