doron doron - 4 months ago 241x
Javascript Question

Convert octet-stream to image

I need to fetch a file using a $http.get.
The data returns as application/octet-stream
But i know this file is an image.

How can i display this file as an image?

I tried

var nuroImage = new Image();
nuroImage.onload = function {
scope.imageSrc = this.src;

funciton(response) {
nuroImage.src = "data:application/octet-stream," +

I get 200ok but the image isn't showing

Is it possible to transform octet-stream to jpeg/png?


You can use XMLHttpRequest() to request image as Blob, URL.createObjectURL() to create a blob URL from response

var nuroImage = new Image;
var request = new XMLHttpRequest();
request.responseType = "blob";
request.onload = function() {
  nuroImage.src = URL.createObjectURL(this.response)
}"GET", "/path/to/image/file");