简体   繁体   English

为什么 ContentSettings cache_control max-age 没有通过 Python 在 Azure 存储 blob 中得到尊重?

[英]Why isn't ContentSettings cache_control max-age being honored in Azure storage blob via Python?

I can't seem to activate Cache-Control max-age in an Azure storage blob in Python via the following code:我似乎无法通过以下代码在 Python 中的 Azure 存储 blob 中激活 Cache-Control max-age

 contentSettings = ContentSettings(cache_control="max-age=86400")  
 containerClient.upload_blob(blobname, theBytes, length=byteCount, 
        overwrite=True, content_settings=contentSettings)

In the web based Azure storage browser, it appears max-age is correctly set:在基于 Azure 存储浏览器的 web 中,显示max-age设置正确: Azure 存储浏览器

However, max-age doesn't seem to be propagated to a browser client when the blob is downloaded.但是,下载 blob 时, max-age似乎不会传播到浏览器客户端。 The file is downloaded correctly but is never cached in the client.该文件已正确下载,但从未缓存在客户端中。 If it matters, I'm using to axios to retrieve the file:如果重要的话,我正在使用 axios 来检索文件:

axios.get(url, { responseType: "arraybuffer" })...

Here's the chrome developer.network view of the file.这是文件的 chrome developer.network 视图。 Notice max-age is missing:注意max-age缺失:

铬合金

One other oddity: The Azure doc for ContentSettings contains the phrase: If the cache_control has previously been set for the blob, that value is stored.另一个奇怪之处: ContentSettings的 Azure 文档包含以下短语:如果先前已为 blob 设置了 cache_control,则存储该值。 Which means what exactly?这到底是什么意思?

What am I doing wrong?我究竟做错了什么?

One possible reason for this could be the CORS settings which is preventing response headers being exposed to the client.一个可能的原因可能是 CORS 设置阻止了响应标头暴露给客户端。

Please check the Exposed Headers CORS settings for blob service on the storage account and make sure all x-ms-* response headers are exposed.请检查存储帐户上 blob 服务的公开标Exposed Headers CORS 设置,并确保公开所有x-ms-*响应标头。

You can also try by setting * (ie all response headers) for exposed header CORS setting.您也可以尝试通过设置* (即所有响应标头)来暴露 header CORS 设置。

Thanks for the suggestion Gaurav.感谢 Gaurav 的建议。 It turned out the problem was (as is usually the case) my own stupidity.原来问题是(通常情况下)是我自己的愚蠢。 I was fetching the file via an ASP.net core controller/service and this wasn't propagating the Etag and Cache-Control values fetched from the Azure blob.我通过 ASP.net 核心控制器/服务获取文件,这并没有传播从 Azure blob 获取的EtagCache-Control值。

It seems curious there doesn't seem to be an easy way to do this.似乎很好奇似乎没有一种简单的方法可以做到这一点。 All of the Azure blob ASP.net core examples I found manually copy over the individual blob properties rather than automatically propagating them.我发现的所有 Azure blob ASP.net 核心示例都是手动复制各个 blob 属性,而不是自动传播它们。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用python SDK接收Azure队列:ValueError:无法将字符串转换为float:max-age = 31536000 - Azure queue receiving with python SDK: ValueError: could not convert string to float: max-age=31536000 无法通过Python WebJob中的azure-storage包访问blob存储 - Can't access blob storage via azure-storage package in Python WebJob Python 代码通过 azure 自动化运行手册连接 azure blob 存储 - Python code to connect azure blob storage via azure automation runbook 通过python API列出azure blob存储中的虚拟文件夹 - list virtual folders in azure blob storage via python API 如何通过 Python 中的 URL 下载 Azure Blob 存储文件? - How to download an Azure Blob Storage file via URL in Python? Python:为什么不加载此子模块? - Python: Why isn't this submodule being loaded? 为什么在python中没有针对__max__的特殊方法? - Why isn't there any special method for __max__ in python? Azure 通过 Python API - 设置存储帐户属性 - 允许 blob 公共访问禁用 - Azure via Python API - Set Storage Account Property - Allow blob public access To Disabled 使用 Python 的 azure httptrigger blob 存储 - azure httptrigger blob storage using Python 使用 Python 的 Azure 服务主体和 storage.blob - Azure service principal and storage.blob with Python
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM