JSFiddle - React, Tailwind, and code Playground
JavaScript
var xhr = new XMLHttpRequest();
xhr.open( "GET", "http://fiddle.jshell.net/img/logo.png", true );
xhr.responseType = "arraybuffer";
// Simulate a call to Dropbox or other service that can
// return an image as an ArrayBuffer.
var xhr = new XMLHttpRequest();
xhr.open( "GET", "http://fiddle.jshell.net/img/logo.png", true );
xhr.responseType = "arraybuffer";
xhr.onload = function(){
var arrayBufferView = new Uint8Array( this.response );
var blob = new Blob( [ arrayBufferView ], { type: "image/jpeg" } );
var imageUrl = (window.URL || window.webkitURL).createObjectURL( blob );
var img = document.querySelector('#test');
img.src = imageUrl;
}
xhr.onload = function( e ) {
// Obtain a blob: URL for the image data.
var arrayBufferView = new Uint8Array( this.response );
var blob = new Blob( [ arrayBufferView ], { type: "image/jpeg" } );
var urlCreator = window.URL || window.webkitURL;
var imageUrl = urlCreator.createObjectURL( blob );
var img = document.querySelector( "#test" );
img.src = imageUrl;
};
xhr.send();