I am new to development using Angular 4. I am facing an issue while getting a response from API about displaying an image. In the API, an image file has an input-stream file. I don't know how to retrieve it and display it properly.
Can you anyone resolve it?
I tried this:
Image.Component.ts:
this.http.get('http://localhost:8080/xxx/download/file/596fba76ed18aa54e4f80769') .subscribe((response) => { var blob = new Blob([response.text()], {type: "image/png"}); console.log(blob); console.log(window.btoa(blob.toString())); });
Results in this => W29iamVjdCBCbG9iXQ==
, but it is not the correct format
and tried this also:
this.http.get('http://localhost:8080/xxx/download/file/596fba76ed18aa54e4f80769').map(Image=>Image.text())
.subscribe(data => {
console.log((data.toString()));
});
Which has this result =>
����\ExifII*��7 ��DuckyK��fhttp://ns.adobe.com/xap/1.0/<?xpacket begin="" id="W5M0MpCehiHzreSzNTczkc9d"?> <x:xmpmeta xmlns:x="adobe:ns:meta/" x:xmptk="Adobe XMP Core 5.3-c011 66.145661, 2012/02/06-14:56:27 "> <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"> <rdf:Description rdf:about="" xmlns:xmpMM="http://ns.adobe.com/xap/1.0/mm/" xmlns:stRef="http://ns.adobe.com/xap/1.0/sType/ResourceRef#" xmlns:xmp="http://ns.adobe.com/xap/1.0/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmpMM:OriginalDocumentID="xmp.did:0280117407206811A2188F30B3BD015B" xmpMM:DocumentID="xmp.did:E2C71E85399511E7A5719C5BBD3DDB73" xmpMM:InstanceID="xmp.iid:E2C71E84399511E7A5719C5BBD3DDB73" xmp:CreatorTool="Adobe Photoshop CC 2014 (Windows)"> <xmpMM:DerivedFrom stRef:instanceID="xmp.iid:7092a9cd-b3fd-bb49-b53c-9b6e1aa1ac93" stRef:documentID="adobe:docid:photoshop:40615934-3680-11e7-911d-f07c687d49b8"/> <dc:rights> <rdf:Alt> <rdf:li xml:lang="x-default"> </rdf:li> </rdf:Alt> </dc:rights> <dc:creator> <rdf:Seq/> </dc:creator> </rdf:Description> </rdf:RDF> </x:xmpmeta> <?xpacket end="r"?>���Photoshop 3.08BIMJZ%Gt6 8BIM%�<".}��νz��܌��Adobed����
but I used to encode using window.btoa, it should be error like not latin range.
DomSanitizer.bypassSecurityTrustUrl
to fix it. – Sycamore