Blazor web assembly getting images from the server securely

Bradley Plett 36 Reputation points
2021-10-16T18:07:46.017+00:00

I have a web assembly securely communicating with the hosting server's API, and it's all working well. However, I need to be able to display images that are dynamically generated on the server (I have an API endpoint that generates them), and it seems that on the client all I have is the "<img src=...>" tag to do that. Sadly all that does is produce a 401, since the request for an image doesn't include the token. How do I solve this?

I realize I may not have explained the scenario very well, so feel free to ask clarifying questions.

Thanks a lot!

Blazor
Blazor
A free and open-source web framework that enables developers to create web apps using C# and HTML being developed by Microsoft.
1,406 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Bruce (SqlWork.com) 57,166 Reputation points
    2021-10-18T14:44:13.293+00:00

    While it will increase the download size, you can return the image as a dataurl, and set the source.

    Another option is to include a unique token in the url. The blazor code would call the server to get the token. The token would have a timeout inside it.