有人可以告诉我如何在Azure blob存储中启用cors吗?我试过以下但是没有用
ServiceProperties propers = new ServiceProperties();
CorsRule cr = new CorsRule();
List<String> allowedHeaders = new ArrayList<String>();
allowedHeaders.add(CorsHttpMethods.PUT.name());
allowedHeaders.add(CorsHttpMethods.POST.name());
allowedHeaders.add(CorsHttpMethods.DELETE.name());
allowedHeaders.add(CorsHttpMethods.GET.name());
cr.setAllowedHeaders(allowedHeaders);
List<String> allowedOrigin = new ArrayList<String>();
allowedOrigin.add("*");
cr.setAllowedOrigins(allowedOrigin);
cr.setMaxAgeInSeconds(600);
CorsProperties corsprop = new CorsProperties();
corsprop.getCorsRules().add(cr);
blobClient.uploadServiceProperties(propers);
这项工作对我来说如下
private static ServiceProperties getCORS() {
ServiceProperties propers = new ServiceProperties();
CorsProperties corsprop = propers.getCors();
CorsRule cr = new CorsRule();
List<String> allowedHeaders = new ArrayList<String>();
allowedHeaders.add("x-ms-*");
List<String> exposedHeaders = new ArrayList<String>();
exposedHeaders.add("x-ms-*");
cr.setAllowedHeaders(allowedHeaders);
cr.setExposedHeaders(exposedHeaders);
EnumSet<CorsHttpMethods> allowedMethod = EnumSet.of(CorsHttpMethods.PUT);
cr.setAllowedMethods(allowedMethod);
List<String> allowedOrigin = new ArrayList<String>();
allowedOrigin.add("*");
cr.setAllowedOrigins(allowedOrigin);
cr.setMaxAgeInSeconds(600);
corsprop.getCorsRules().add(cr);
//corsprop.getCorsRules().add(cr);
propers.setCors(corsprop);
return propers;
}
现在我可以使用以下代码进行设置。我可以使用它,当我从Gaurav创建的javascript客户端上传文件时:http://gauravmantri.com/2013/02/16/uploading-large-files-in-windows-azure-blob-storage-using-shared-access-signature-html-and-javascript/
CloudStorageAccount storageAccount;
storageAccount = CloudStorageAccount.parse(storageConnectionString);
CloudBlobClient blobClient = storageAccount.createCloudBlobClient();
CloudBlobContainer container = blobClient.getContainerReference(containerName);
ServiceProperties propers = getCORS();
SharedAccessBlobPolicy policy = createPolicy();
blobClient.uploadServiceProperties(propers);