Created
August 1, 2016 03:52
-
-
Save mingliangguo/8e4e2730878de5fd5e42cb7e19e002e2 to your computer and use it in GitHub Desktop.
A simpler version to get box thumbnail URI
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var xhr = new XMLHttpRequest(); | |
xhr.open("GET", "https://api.box.com/2.0/files/76537235577/thumbnail.png?min_height=150&min_width=150", true); | |
xhr.setRequestHeader("Authorization", "Bearer your_access_token"); | |
xhr.responseType = "arraybuffer"; | |
xhr.onload = function(e) { | |
if (this.status == 200) { | |
var uInt8Array = new Uint8Array(this.response); | |
var blob = new Blob([uInt8Array], {type: 'application/octet-binary'}); // pass a useful mime type here | |
var url = URL.createObjectURL(blob); | |
document.getElementById("preview").src=url; | |
} | |
}; | |
xhr.send(); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment