I have been using the insertImage function to insert images saved on my Drive into Google sheets daily for several months. Today it has stopped working with the following error message:
Exception: The image could not be inserted. Please verify it is valid and try again.
The procedure that has always worked was to get the file ID, retrieve the link, fetch the image from the link and insert the image. This is illustrated in the code below:
var blob = DriveApp.getFileById(fileID).getBlob()
var width = 340;
var link = Drive.Files.get(fileID).thumbnailLink.replace(/\=s.+/, "=s" + width);
var blob2 = UrlFetchApp.fetch(link).getBlob()
var the_image = TemplateSheet.insertImage(blob2, 3, 13, 110, 0);
When I visit the "link" I am directed to the image as expected. I can also save "blob2" as an image and use it in other ways without any errors. Can anyone assist with a solution to the error I am receiving?
Try this:
function myFunction() {
var blob = DriveApp.getFileById("fileid");
var width = 340;
//Insert and resize image
SpreadsheetApp.getActiveSheet().insertImage(blob, 3, 13, 110, 0).setWidth(width);
}
Reference: