Insert Image from Url in Docs

826 views
Skip to first unread message

sben...@bbchs.org

unread,
Oct 19, 2022, 5:22:36 PM10/19/22
to Google Apps Script Community
Is there a way to insert an image in docs from a url using Apps Script?  I can not find any methods for it.

Clark Lind

unread,
Oct 25, 2022, 7:06:43 PM10/25/22
to Google Apps Script Community
I was able to get this to work as an example. You have to retrieve the image as a blob, then insert the blob into the Doc. If you want to add the url, you can add that to the last line

async function addImage() {
   const tempImage = await UrlFetchApp.fetch(url)
   const image = tempImage.getBlob();
   const docBody = DocumentApp.getActiveDocument().getBody()
   const inlineImage = docBody.appendImage(image);
   inlineImage.setHeight(300).setWidth(200);    //.setLinkUrl(url)
 }
Reply all
Reply to author
Forward
0 new messages