0

I am trying to re-design the flow we currently have in the app, where GET /image/123 endpoint would download image from Azure Blob Storage and serve it back to the client to use SAS tokens to offload our BE.

Initially I tried doing it in a way that the endpoint simply redirects clients to the right SAS token, but unfortunatelly this was causing CORS errors on the client side, as the redirect was moving the client to the different domain. I then switched to another approach, where GET /image/123/url endpoint would give SAS token to the client, so it can load the image, the problem is that in my initial approach I was easily able to provide client-side cache for the images using cache-control header, but this time I don't know how to do it, since the client is calling Azure directly and as a result it re-downloads the image every time. I tried applying cache-control on the /image/:imageId/url endpoint, so it generates SAS tokens once in a while (making sure tokens expiration is longer than the cache duration) and that works, but the client is still downloading the same image multiple times. Is there any way I can make it work, or my approach is wrong and there are some other ways of doing that? Thanks!

  • Szopa Can you share your code in the question? – Dasari Kamali Aug 31 '23 at 10:58
  • 1
    OK, I think I found a solution. Apparently, the function I used to obtain the SAS token supports applying cache control header (cf https://learn.microsoft.com/en-us/javascript/api/@azure/storage-blob/?view=azure-node-latest#@azure-storage-blob-generateblobsasqueryparameters), so I tried adding and it seems to be working just fine now – Michał Szopa Aug 31 '23 at 12:06

0 Answers0