0

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

  1. (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);

  1. Any other solutions ??? - I need to be able open new Tab with PNG/PDF etc. AND download it to disk also
Yoorek
  • 1,003
  • 1
  • 12
  • 30
  • Is it possible that the web service is returning some additional data that it wasn't before? I can't see why your 1st solution wouldn't work. – Ragdata Sep 14 '15 at 14:06
  • http://stackoverflow.com/q/27810163/575527 - Three APIs: FileReader, Blob and Url. – Joseph Sep 14 '15 at 14:09

0 Answers0