Inserting a Google Drive image into a document using Google Apps Script
google-apps-script
Solution
To insert files from Drive do not use the HTTP route unless the file has been made public via drive hosting
Insert use the built in apis to read the file's blog and insert the img.
Here is an example of inserting a jpg from my drive (or a file I have access to) to a document.
function insertImageFromDrive(){
var fileId = '0B_dyIOzoasdfasdfPVTMxdTVXWDg';
var img = DriveApp.getFileById(fileId).getBlob();
DocumentApp.getActiveDocument().getBody().insertImage(0, img);
}
This will insert an image at the top of the document. To get more control over the cursor/selection replacement see this blog post.
Problem
I am trying to pro grammatically insert an image into a document. I can get this to work fine with an image with a URL such as http://www.geeks-on-wheels.net/wp-content/uploads/apple.jpg. The problem comes when trying to use an image located on my Google Drive. The URL looks like this: https://docs.google.com/a/finance-in-motion.com/file/d/0B5sPSMZ9pf-QMG9GOVROakxQYmM/edit or https://docs.google.com/a/finance-in-motion.com/file/d/0B5sPSMZ9pf-QMG9GOVROakxQYmM/edit?usp=sharing. The script doesn't seem to know what to do with it and throws an error. Any help would be appreciated.