It's been a week since I started using Azure Storage.
The other day, I wrote How to set CORS for Azure storage service in Python, but today I want to write about how to set Cache-Control. think.
Before using Azure Storage, I used to specify ʻexpires` in Nginx to cache images and other static files on the browser side, but after installing Azure Storage, requests for static files are skipped every time. I noticed that I was out.
Browser cache is essential for crisp browsing. As a result of investigation, it seems that you should specify the property x-ms-blob-cache-control
when saving the BLOB.
As a result, when written in python, the code looks like the following.
from azure.storage.blob import BlobService
destination = 'File location'
name = 'file name'
source = 'Path of files to upload to Azure Storage'
content_type = 'image/jpeg' #Set appropriately according to the type of file to be uploaded
client = BlobService(
account_name='account name',
account_key='Key'
)
client.put_block_blob_from_path(
destination,
name,
source,
x_ms_blob_content_type=content_type,
x_ms_blob_cache_control='public, max-age=0'
)
Recommended Posts