8

I set to my project json web token authentication. I secured all requests under "private" path. What is the best way to download an image from client using tag img and attribute src.

<img src="/private/test.jpg" />

The only solution I have so far is to set a coookie on the client with token value and instead of private to access public path. Than on the server I will get the cookie value and make a new request with proper token set in the header toward my private path.

Is there more elegant way ?

user732456
  • 2,638
  • 2
  • 35
  • 49

1 Answers1

0

The proper way is to make a javascript call (e.g. ajax) and get the base64 of that image using the token and then set the source of the image with that base64 string, like this:

<img src="data:image/png;base64, YOUR_BASE64_IMAGE_HERE"/>
Hesam Kashefi
  • 620
  • 8
  • 15