I have REST service endpoint serving binary data (files e.g PDF, JPG, PNG etc) REST service is secured with token based authentication. Without security I could simply get PNG and open it in new window with
<a href="RESTURL/item/1/file" target="_blank">
But now, after we implemented security I get "Authorization error" because I have to pass "Authorization" header with "Bearer TOKEN"...
I thought of 2 solutions (I have ZERO experience with binary data, images etc.):
1.(naive) use existing endpoint to download binary data and open it like this:
let uriContent = "data:image/jpg," + result;
window.open(uriContent);
where result is response from REST service returning binary data.
Doesn't work - I get jibberish in opened window
- (not possible to try now) change REST service to return Base64 and open it with:
let uriContent = "data:image/jpg;base64," + result;
window.open(uriContent);
- Any other solutions ??? - I need to be able open new Tab with PNG/PDF etc. AND download it to disk also