Add Cache-Control and Expires headers to Azure Storage Blobs

前端 未结 8 1712
刺人心
刺人心 2020-12-04 21:48

I\'m using Azure Storage to serve up static file blobs but I\'d like to add a Cache-Control and Expires header to the files/blobs when served up to reduce bandwidth costs.

相关标签:
8条回答
  • 2020-12-04 22:16

    Set storage blob cache-control Properties by PowerShell script

    https://gallery.technet.microsoft.com/How-to-set-storage-blob-4774aca5

    #creat CloudBlobClient 
    Add-Type -Path "C:\Program Files\Microsoft SDKs\Windows Azure\.NET SDK\v2.3\ref\Microsoft.WindowsAzure.StorageClient.dll" 
    $storageCredentials = New-Object Microsoft.WindowsAzure.StorageCredentialsAccountAndKey -ArgumentList $StorageName,$StorageKey 
    $blobClient =   New-Object Microsoft.WindowsAzure.StorageClient.CloudBlobClient($BlobUri,$storageCredentials) 
    #set Properties and Metadata 
    $cacheControlValue = "public, max-age=60480" 
    foreach ($blob in $blobs) 
    { 
      #set Metadata 
      $blobRef = $blobClient.GetBlobReference($blob.Name) 
      $blobRef.Metadata.Add("abcd","abcd") 
      $blobRef.SetMetadata() 
    
      #set Properties 
      $blobRef.Properties.CacheControl = $cacheControlValue 
      $blobRef.SetProperties() 
    }
    
    0 讨论(0)
  • 2020-12-04 22:25

    Sometimes, the simplest answer is the best one. If you just want to manage a small amount of blobs, you can use Azure Management to change the headers/metadata for your blobs.

    1. Click on Storage, then click on the storage account name.
    2. Click the Containers tab, then click on a container.
    3. Click on a blob, then click on Edit at the bottom of the screen.

    In that edit window, you can customize the Cache Control, Content Encoding, Content Language, and more.

    Note: you cannot currently edit this data from the Azure Portal

    0 讨论(0)
提交回复
热议问题