Hello Vasile
When utilizing a blob URL (even with a SAS token) directly within an HTML src attribute (such as for <img>, <video>), the browser frequently executes a "simple request" and does not consistently issue a CORS preflight OPTIONS request.
It may directly retrieve the resource. If the resource successfully loads (which it does, given that your SAS token is valid), the browser generally permits it to be displayed or played, even in the absence of an explicit CORS header, provided that the resource is not subsequently accessed.
As Showen in the error message from origin has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.
indicates that your Azure Storage account, where the blobs are stored, is not configured to allow requests from your frontend's domain.
CORS Configuration:
- In the search bar at the top, type the name of your Storage Account and select it. In the left-hand menu of your storage account, under the "Data storage" section, select "Browser" (for Blob service) or "Resource sharing (CORS)". The "Resource sharing (CORS)" blade is where you manage CORS rules for all storage services (Blob, File, Queue, Table).
- Since your issue is with blobs, click on "Blob service" under the "Services" tab, then select "CORS". You will see a section titled "CORS rules". Click on "Add rule" (or if there are existing rules, you can edit one or add a new one).
Post which you will need to establish a rule that permits the origin of your frontend to access the blobs. During development or testing phases, you may opt for a more lenient rule at first; however, for production environments, it is advisable to adopt the most restrictive approach possible.
- Enter the exact domain(s) from which your frontend application is served.
-
http://localhost:<port>
(e.g.,http://localhost:3000
) - Select the HTTP methods your frontend will use to interact with the blobs. For fetching, you definitely need
GET
. If you also upload, you might needPUT
,POST
, etc. SelectGET
andOPTIONS
at a minimum. For general access, you can use*
to allow all headers (less secure). - For stricter control, you might need to specify headers that your frontend sends (e.g.,
x-ms-blob-type
,Content-Type
). Ifreact-audio-visualize
sends custom headers, you'll need to list them here. A common safe default forfetch
isContent-Type,Accept
. - Click "Save" at the top of the CORS settings blade.
After saving, it might take a few minutes (up to 5-10 minutes) for the CORS rule to propagate across Azure Storage.
Hope the above answer helps! Please let us know do you have any further queries.
Please do not forget to "Accept the answer” and “up-vote” wherever the information provided helps you, this can be beneficial to other community members.