mingliangguo
8/3/2016 - 2:45 AM

An even simpler version to get box thumbnail URL (or any other binary content)

An even simpler version to get box thumbnail URL (or any other binary content)

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 = "blob";

xhr.onload = function(e) {
  if (this.status == 200) {
    var blob = xhr.response;
    var url = URL.createObjectURL(xhr.response);

    document.getElementById("preview").src = url;
  }
};

xhr.send();