Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
//first off, get the Base64 image value from the Web API method
url: "https://" + + "/api/values?path=" + url
}).done(function (data) {
//data represents the Base64 value of the image
if (data != null) {
if (data.length > 0) {
var imageOXmlTemplate;
var templateRequest = new XMLHttpRequest();
var base64;
//Get the Open XML image snippet'GET', '/Scripts/App/Templates/Image.xml', false);
if (templateRequest.status === 200) {
imageOXmlTemplate = myOOXMLRequest.responseText;
//Save the Base64 value in a local variable (after removing the content type prefix)
base64 = (data.substr(data.indexOf(',') + 1));
Here you would update the snippet, with a find and replace using the file type (PNG, JPEG etc..).
Maybe something like...
imageOXmlTemplate = imageOXmlTemplate.replace(/{format}/g, url.substr(url.lastIndexOf('.') + 1));
{ coercionType: "ooxml" },
function (asyncResult) {
if (asyncResult.status == "failed") {
//maybe do something?
} else {
//you should be able to see the image in your document
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment