I am storing json blobs on azure which I am accessing via XHR. While trying to load these blobs I am getting this error:
XMLHttpRequest cannot load http://myazureaccount.blob.core.windows.net/myjsoncontainer/myblob.json?json. Origin http://localhost is not allowed by Access-Control-Allow-Origin.
Is there any way to set the Access-Control-Allow-Origin header of a blob returned by azure?
Windows Azure Storage added CORS support on November 26, 2013: Cross-Origin Resource Sharing (CORS) Support for the Windows Azure Storage Services. More details and C#/JavaScript samples - Windows Azure Storage: Introducing CORS.
The CORS options can be set on a storage account using the Windows.Azure.Storage client library version 3.0.1.0 or later, available from NuGet, using something similar to the following pseudocode:
var storageAccount = CloudStorageAccount.Parse(
"DefaultEndpointsProtocol=https;AccountName=ABC;AccountKey=XYZ");
var blobClient = storageAccount.CreateCloudBlobClient();
var serviceProperties = blobClient.GetServiceProperties();
serviceProperties.Cors.CorsRules.Clear();
serviceProperties.Cors.CorsRules.Add(new CorsRule() {
AllowedHeaders = { "..." },
AllowedMethods = CorsHttpMethods.Get | CorsHttpMethods.Head,
AllowedOrigins = { "..." },
ExposedHeaders = { "..." },
MaxAgeInSeconds = 600
});
blobClient.SetServiceProperties(serviceProperties);
Not currently but Scott Hanselman, Program Manager for Azure, has confirmed support for this is coming soon on Feb 4th 2013.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With