Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Azure storage. Got 403 [url] (CORS not enabled or no matching rule found for this request.)

I am developing some web-page that allows to upload files from client side to my azure storage directly. My files are stored on Azure BLOB Storage in Portal. For this I am using 'azure-storage' v2.8.1 package from npm.

While I am trying to create container:

    const blobService = AzureStorage.createBlobServiceWithSas(storageUri, sasToken)
    blobService.createContainerIfNotExists(containerName, { publicAccessLevel: 'blob' }, (error, result, response) => {.....})

I got errors:

  1. OPTIONS [url to my storage] 403 (CORS not enabled or no matching rule found for this request.)

  2. Failed to load [url to my storage]: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.

I am sure that blob connection string is correct - I checked it. In addition I know that I can edit CORS for my storage on azure.portal. Currently it is empty.

Should I need to add/edit there some CORS? Do someone know solution?

like image 903
Alexandr Mendelevych Avatar asked Jan 02 '23 07:01

Alexandr Mendelevych


1 Answers

Should I need to add/edit there some CORS? Do someone know solution?

Yes, you need to add the CORS setting for storage blob service. By default, CORS is disabled for each service. We could get more information about CORS from this article.

Note: CORS is not supported for Premium Storage accounts.

We also could set it from Azure portal. More details please refer to the screenshot.

enter image description here

like image 137
Tom Sun - MSFT Avatar answered Jan 22 '23 10:01

Tom Sun - MSFT