A
A
ajky2017-03-10 15:27:13
JavaScript
ajky, 2017-03-10 15:27:13

How to display images received from a request with Content-Type: application/image in Angular2?

Perhaps it would be easier if they were not in the text, but the point is that in the markdown text there are pictures that are indicated not by the address, but by the id of the picture. I make a request to the address, I get a response like application/image .
Everything I screwed up:

.subscribe(
    (data:any) => {
        let image = window.URL.createObjectURL(new Blob([data.arrayBuffer()], {
            type: "application/image"
        }))

        return '<img src="'+image+'">';
    }
);

Displays a link of the form: blob: server.name/xxxxxx-xxxx-xxxxxxxxx-xx
Can I somehow finish it so that it still displays the picture, and not the contents of the file?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
O
ozknemoy, 2017-03-22
@ozknemoy

the blob constructor is not cross-browser friendly, if it doesn't confuse (but it should) then it can be converted to base 64 which can be shoved into the src of the photo

var reader = new window.FileReader();
 reader.readAsDataURL(blob); 
 reader.onloadend = function() {
                base64data = reader.result;                
                console.log(base64data );
  }

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question