Edit json for Resource Sharing (CORS) on Blob Service

Jeff Schulz 0 Reputation points
2023-04-10T23:39:05.36+00:00

I am entering one or more lines and filling in the fields for oneor mor cors rules for my blob service ...
but, I would like to edit/download the .json file instead. How can i do that, do i have to go thru the rest apis ? ex. there is 'JSON view' on storage main page/

Azure Blob Storage
Azure Blob Storage
An Azure service that stores unstructured data in the cloud as blobs.
2,639 questions
{count} votes

1 answer

Sort by: Most helpful
  1. KarishmaTiwari-MSFT 19,032 Reputation points Microsoft Employee
    2023-04-12T05:49:22.7533333+00:00

    @Jeff Schulz Thanks for posting your query on Microsoft Q&A.

    Currently there isn't a way to update the CORS rules via JSON view on Azure portal.
    But you can use Azure CLI or Azure PowerShell to update the CORS rules, if you do not want to go the REST API way. For example, to update CORS rules using Azure PowerShell,

    Set Storage context

    $ctx1=New-AzStorageContext -StorageAccountName "sname" -StorageAccountKey "abc"
    

    Get Storage CORS rule

    $CorsRules = Get-AzStorageCORSRule -ServiceType Blob -Context $ctx1      
    

    View existing CORS rules if any.

    Write-Output $CorsRules 
    

    Output:

    AllowedOrigins  : {127.0.0.1}
    AllowedHeaders  : {*}
    ExposedHeaders  : {}
    AllowedMethods  : {Get}
    MaxAgeInSeconds : 0
    

    Update CORS rule:

    $CorsRules[0].AllowedMethods = @("Get", "Connect", "Merge")        
    Set-AzStorageCORSRule -ServiceType Blob -CorsRules $CorsRules -Context $ctx1
    $CorsRules = Get-AzStorageCORSRule -ServiceType Blob -Context $ctx1                                                                                   Write-Output $CorsRules  
    

    Output:

    AllowedOrigins  : {127.0.0.1}
    AllowedHeaders  : {*}
    ExposedHeaders  : {}
    AllowedMethods  : {Get, Connect, Merge}
    MaxAgeInSeconds : 0
    

    This way, you can update the CORS rules.

    You may also find these documents helpful:

    If you have any questions, please let us know in the "comments" and we would be happy to help you. Comment is the fastest way of notifying the experts.

    If this helps, please 'Accept answer', 'mark as helpful' so that it can help others in the community looking for help on the same topic.

    0 comments No comments