As you all probably know, google hosting is going away at the end of the month. However I've got the impression that the webcontentlink meta property of a file will still work as a link to an image.

To get the link by apps script, you need to enable the advanced drive service, and you can get the webcontent link as per this app. So you can have a little webapp to tell you the url for any file which you can then copy into your html code.

function doGet(e) {

var id = e && e.parameter && e.parameter.id ? e.parameter.id : "id missing";
var mode = e && e.parameter && e.parameter.mode ? e.parameter.mode : "details";
var file = getWebContentLink(id);

if (mode === "image") {
return HtmlService
.createHtmlOutput('<img src="' + file.webContentLink + '">')
}
else {
return ContentService
.createTextOutput(JSON.stringify(file))
.setMimeType(ContentService.MimeType.JSON);
}
}
function getWebContentLink(id) {
// Drive.Files.get(fileId)
return Drive.Files.get(id, {
fields:"id,title,webContentLink"
});

}

You can then use the webcontentlink as the url for the hosted file and it seems to work.

Im not sure what'll happen with unsigned in users. For a test, I've published this webapp to run as me, so i'm assuming it will work on any files you've got as public.

If anyone wants to have a go, then here's the app - this modes returns detail on the file so you can use the link.
https://script.google.com/macros/s/AKfycbz88m2Ng_V6t7_OviLRgK9S8bttVYmqA9pdraVlXhG9t0xTIFuH/exec?id=0B92ExLh4POiZMmRzSC1QRk5TLXM

this one renders the image
https://script.google.com/macros/s/AKfycbz88m2Ng_V6t7_OviLRgK9S8bttVYmqA9pdraVlXhG9t0xTIFuH/exec?id=0B92ExLh4POiZMmRzSC1QRk5TLXM&mode=image


any thoughts?

#gde #googleappsscript #blogpost
Shared publiclyView activity