Getting CORS Errors When Trying to Check Download on a Storage Emulator

I am trying to test download functionality for html5, angularjs application using azure storage emulator. For some reason, every time I send the file to azure the generated url for localhost, I keep getting CORS errors. Now in the cloud instance, I used the following code to add CORS support, and it works:

blobServiceProperties.Cors.CorsRules.Add(new CorsRule() { AllowedHeaders = new List<string>() { "*" }, //ExposedHeaders = new List<string>() {"*"}, AllowedMethods = CorsHttpMethods.Post | CorsHttpMethods.Put | CorsHttpMethods.Get | CorsHttpMethods.Delete, AllowedOrigins = new List<string>() { "http://example.com" }, MaxAgeInSeconds = 3600 }); 

When I try to run this for an emulator, I get errors indicating that this is not allowed. Should I configure CORS for the emulator, and if so, how can I do this since the code above does not work with the emulator?

+5
source share
1 answer

One thing I wanted to clarify according to the MSDN documentation

"Support for Azure Services supports Cross-Origin Resource Sharing (CORS) for Blob, Table, and Queue. File Services supports CORS starting in version 2015-02-21."

And further to this

You can set CORS rules individually for each storage service by calling Set Service Blob Service Properties, Set File Service Properties, Set Queue Service Properties and Set Table Service Properties. After you set the CORS rules for the service, a properly authenticated request against the service from another domain will be checked to determine if it is allowed according to the rules you specify.

So, I'm curious if the service is a File service or just a blob service, you seem to have included CORS for the blob service according to the provided code snippet. But you didn’t put the code snippet for the download function, if you do it using AJAX, you need to set the header type to use the Azure function as a blob, otherwise the cross-source request may be blocked at the very end of the request if it cannot match service response header type.

Also check out these two links

Windows Azure Service CORS Example

CORS for Azure Storage

0
source

Source: https://habr.com/ru/post/1238792/


All Articles