Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Any way to set access-control-allow-origin for a windows azure blob

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?

like image 428
morpheus Avatar asked Jul 29 '11 18:07

morpheus


2 Answers

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);
like image 152
Axel Rietschin Avatar answered Oct 25 '22 05:10

Axel Rietschin


Not currently but Scott Hanselman, Program Manager for Azure, has confirmed support for this is coming soon on Feb 4th 2013.

like image 43
bkaid Avatar answered Oct 25 '22 05:10

bkaid