json web token + img src
Asked Answered
W

1

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 ?

Worst answered 28/1, 2015 at 13:16 Comment(0)
K
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"/>
Kick answered 12/8, 2019 at 4:18 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.