I'm hoping to set the src attribute of an to a data uri (data:image/png;base64,etc..) and I'm running into an error:
Rejecting .setAttribute( src , data:image/png;base64,image_data... )
I tested out a small code snippet on the Caja Playground, but it also was unable to load a data uri.
Code.gs
// Script-as-app template.
function doGet() {
return HtmlService.createTemplateFromFile('index').evaluate();
}
function fetch(url) {
var response = UrlFetchApp.fetch(url);
return Utilities.base64Encode(response.getContent());
}
Index.html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>Image Test</title>
<script type="text/javascript" src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.6.2.min.js"></script>
<script>
$(document).ready(function() {
$("#test").click(function() {
google.script.run.withSuccessHandler(function(data) {
window.console.log(data);
$("#photo1").attr("src", "data:image/png;base64," + data);
}).fetch("http://upload.wikimedia.org/wikipedia/commons/thumb/3/30/Googlelogo.png/320px-Googlelogo.png");
});
});
</script>
</head>
<body>
<button id="test">Test</button>
<img id="photo1" width="320" height="110" />
<img id="photo2" width="320" height="110" src="http://upload.wikimedia.org/wikipedia/commons/thumb/3/30/Googlelogo.png/320px-Googlelogo.png" />
</body>
</html>
Public link to Google Apps Script - (It shouldn't require account login...)
I'm beginning to think that this is not a supported operation.