2016-12-15 120 views
3

我正在嘗試設置CORS規則爲我的存儲帳戶這裏下配置CORS建議使用Azure的資源管理器工具:https://docs.microsoft.com/en-us/azure/app-service-api/app-service-api-cors-consume-javascript配置CORS使用Azure的資源管理器模板

通過增加財產CORS:

"resources": [ 
    { 
     "type": "Microsoft.Storage/storageAccounts", 
     "sku": { 
      "name": "Standard_RAGRS", 
      "tier": "Standard" 
     }, 
     "kind": "Storage", 
     "name": "[parameters('storageAccounts_teststoragejkjk_name')]", 
     "apiVersion": "2016-01-01", 
     "location": "westus", 
     "tags": {}, 
     "properties": { 
      "cors": {"allowedOrigins": ["*"]} 
     }, 
     "resources": [], 
     "dependsOn": [] 
    } 
] 

部署返回成功,我可以看到在Azure Portal中的活動日誌下寫入StorageAccount操作,但Cors規則不會添加到任何地方,並且當我從Azure下載模板時,它沒有此「cors屬性」。

我也試過手動添加科西嘉規則(我需要它只是我的斑點)和自動化腳本(包括deployment.ps)看起來還是一樣的...

如何配置上的斑點一個Cors規則任何建議使用ARM模板存儲?

回答

1

什麼是您的部署客戶端? 如果您使用Powershell來部署ARM(您可能是),爲什麼不使用Set-AzureStorageCORSRule

PS C:\>$CorsRules = (@{ 
[email protected]("x-ms-blob-content-type","x-ms-blob-content-disposition"); 
[email protected]("*"); 
MaxAgeInSeconds=30; 
[email protected]("Get","Connect")}, 
@{ 
[email protected]("http://www.fabrikam.com","http://www.contoso.com"); 
[email protected]("x-ms-meta-data*","x-ms-meta-customheader"); 
[email protected]("x-ms-meta-target*","x-ms-meta-customheader"); 
MaxAgeInSeconds=30; 
[email protected]("Put")}) 

PS C:\> Set-AzureStorageCORSRule -ServiceType Blob -CorsRules $CorsRules

+0

我覺得沒有辦法通過模板來做到這一點,所以我同意你的觀點: – letlampa

+0

我用 設置-AzureStorageCORSRule -servicetype斑點-CorsRules $ CorsRules -Context $ StorageAccountContext – letlampa

+0

@letlampa很高興幫助您:)別忘記標記問題爲答案 – EvertonMc

1

我正在嘗試設置CORS規則爲我的存儲帳戶

我創建了一個類似ARM template創建一個存儲帳戶的資源,我發現,它似乎無法識別/接受CORS和其他屬性(如我定義的val)除accountType屬性。

{ 
    "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#", 
    "contentVersion": "1.0.0.0", 
    "parameters": { }, 
    "variables": { }, 
    "resources": [ 
    { 
     "type": "Microsoft.Storage/storageAccounts", 
     "apiVersion": "2015-06-15", 
     "name": "[concat('storage', uniqueString(resourceGroup().id))]", 
     "location": "[resourceGroup().location]", 
     "properties": { 
     "accountType": "Standard_LRS", 
     "cors": { 
      "allowedHeaders": [ "*" ], 
      "allowedMethods": [ "get", "post", "put" ], 
      "allowedOrigins": [ "*" ], 
      "exposedHeaders": [ "*" ], 
      "maximumAge": 5 
     }, 
     "val": "123" 
     } 
    } 
    ], 
    "outputs": { } 
} 

此外,正如我們所知,我們可以配置一個Cors設定Azure存儲服務(BLOB,表,隊列和文件共享),它似乎並沒有使我們的存儲帳戶配置一個Cors設定直接部署存儲帳戶模板。 enter image description here

0

存儲賬戶CORS目前不是由存儲資源提供支持,因此它無法通過模板來設置。正如弗雷德指出的那樣,CORS只能通過data plane API在服務上設置。

相關問題