title: Cannot add image from Google Drive to a Google Form using Apps Script
body: <p>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:</p>
  
  <pre><code>var img = UrlFetchApp.fetch('https://www.google.com/images/srpr/logo4w.png');
  form.addImageItem().setImage(img);
  </code></pre>
  
  <p>This works o.k. but I want to refer to an image in my Google Drive account.</p>
  
  <p>If I try and use the image share link to a Google Drive image I get an error:</p>
  
  <pre><code>var img = UrlFetchApp.fetch("https://drive.google.com/open?id=0B_u2iAm1LaoZSHd1TTExcDFrbUU");
  form.addImageItem().setImage(img);
  </code></pre>
  
  <blockquote>
    <p>ERROR: "Blob object must have an image content type for this
    operation."</p>
  </blockquote>
  
  <p>And if I try and open the file by it's ID I get a different error: </p>
  
  <pre><code>var img = DriveApp.getFileById("0B_u2iAm1LaoZSHd1TTExcDFrbUU");
  form.addImageItem(img);
  </code></pre>
  
  <blockquote>
    <p>ERROR: "Could not add image, please wait a minute and try again."</p>
  </blockquote>
  
  <p>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.</p>