Add Cache-Control and Expires headers to Azure Storage Blobs

前端 未结 8 1710
刺人心
刺人心 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() 
    }
    

提交回复
热议问题