mingliangguo
8/1/2016 - 3:52 AM

A simpler version to get box thumbnail URI

A simpler version to get box thumbnail URI

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();