I am trying to programmatically add an image from my Google Drive to a Google form. I can get it to work using a reference to a static image URL by using the google example such as:
var img = UrlFetchApp.fetch('https://www.google.com/images/srpr/logo4w.png');
form.addImageItem().setImage(img);
This works o.k. but I want to refer to an image in my Google Drive account.
If I try and use the image share link to a Google Drive image I get an error:
var img = UrlFetchApp.fetch("https://drive.google.com/open?id=0B_u2iAm1LaoZSHd1TTExcDFrbUU");
form.addImageItem().setImage(img);
ERROR: "Blob object must have an image content type for this operation."
And if I try and open the file by it's ID I get a different error:
var img = DriveApp.getFileById("0B_u2iAm1LaoZSHd1TTExcDFrbUU");
form.addImageItem(img);
ERROR: "Could not add image, please wait a minute and try again."
I can't seem to find any documentation about how I can achieve this or what I am doing wrong. I tried changing the sharing settings on the image in my Google Drive to be publicly available. And I have tried to get a static image URL to the image in the Google Drive but the only URL that seems to be available is the share URL which goes to a holding/display page for the image and not the actual image itself.