问题描述

在微软云存储账号的服务中,存储一些静态图片,然后通过App Service访问,但是遇见了400 - condition headers not support 错误。

在单独通过浏览器访问 File Share中的文件,发现第一次可以请求成功,但是第二次刷新后就遇见400错误,第三次刷新的时候又访问成功,如此循环下去。

错误消息为:

This XML file does not appear to have any style information associated with it. The document tree is shown below.

<Error>
<Code>ConditionHeadersNotSupported</Code>
<Message>Condition headers are not supported. RequestId:cf7f3c6e-101a-0052-73db-ea03cf000000 Time:2023-09-19T09:24:55.3527405Z</Message>
</Error>

问题解答

在网络上搜索关键字 “400 Condition headers are not supported. “, 就可以发现很多结果。

其中以 Github的结果(https://github.com/MicrosoftDocs/azure-docs/blob/main/includes/storage-files-condition-headers.md) 和 Stack Overflow (https://stackoverflow.com/questions/43706605/azure-file-storage-error-condition-headers-are-not-supported) 为参考,找到了问题的根源

根源

Conditional headers aren't currently supported. Applications implementing them will need to request the full file every time the file is accessed.
Storage Account 目前不支持条件标头。 实现它们的应用程序将需要在每次访问文件时请求完整的文件。

文章中也给出了解决方案,通过在上传的文件中设置 CacheContorl属性值为 no-cache, no-store, must-revalidate. 目的时告诉浏览器,不要对这个URL的内容进行缓存,必须从源站点重新验证获取最新资源。

  • 所以需要通过 Azure Storage Explorer工具对每一个文件(注意:不能对文件所属的文件夹进行修改)的属性值 【CacheControl】进行修改。

  • 在Stack Overflow中,提出了另一种解决办法,就是在每一次请求的URL后面,增加一个随机参数,以保证每次发出的请求URL不一样,避免了浏览器缓存,因此也不会添加 Conditional Header。

(Source:https://stackoverflow.com/questions/43706605/azure-file-storage-error-condition-headers-are-not-supported

经验证,这种方法是可行的。

但问题在于,这个方法也只能使用一次。

第二次刷新时(如果随即参数不变化),也会遇见400-condition headers not support报错。

所以最后,最好的解决办法还是在Azure Blob File Share的文件中,添加属性值 CacheContorl为 no-cache, no-store, must-revalidate。

  • 如果是新文件,可以在上传的方法中设置CacheControl Properties 。
  • 如果是已经存在的文件,可以通过PowerShell脚本批量修改文件的 CacheControl Properties, 主要是使用

1) 获取指定folder下的全部内容 az storage file list
2) Foreach 循环,如果遇见文件夹,使用递归调用,直至全部文件获取完毕
3) 对文件类型,使用 az storage file update 更改 --content-cache 值

PowerShell脚本示例如下:

## Set the Storage Account name, File Share Name, and the Acceount Key
$account_name = "您的存储账号名称"
$account_key = "您的存储账号密钥"
$file_share_name = "需要修改的文件夹名称" #会修改文件夹中所有文件的content-cache属性值为 "no-cache, no-store, must-revalidate" ## Recursive Call to list all files and update the file properties .
Function UpdateAllFileProperties {
param($foldername)
Write-Host "Start to list this folder - " $foldername
#List all file & folder under this input folder path...
$subfiles = az storage file list -s $foldername --account-name $account_name --account-key $account_key | ConvertFrom-Json
Foreach ($f in $subfiles) { If ($f.type -eq 'file') {
Write-Host "\t" + $f.name
#Update file properties --content-cache "no-cache, no-store, must-revalidate"
az storage file update -p $f.name -s $foldername --account-name $account_name --account-key $account_key --content-cache "no-cache, no-store, must-revalidate"
}
elseif ($f.type -eq 'dir') {
$newfolder = $foldername + '/' + $f.name
Write-Host $newfolder
UpdateAllFileProperties $newfolder
}
else {
Write-Host "Invalid type, coutinue ... "
}
}
} Write-Host "Start ... "
#Start to foreach all files & folders
UpdateAllFileProperties $file_share_name
Write-Host "Complete ... "

执行结果展示动画:

参考资料

Error ConditionHeadersNotSupported from a Web Application using Azure Files from Browser : https://github.com/MicrosoftDocs/azure-docs/blob/main/includes/storage-files-condition-headers.md

Azure File Storage Error: Condition Headers Are Not Supported : https://stackoverflow.com/questions/43706605/azure-file-storage-error-condition-headers-are-not-supported

az storage file : https://learn.microsoft.com/en-us/cli/azure/storage/file?view=azure-cli-latest#az-storage-file-list()

Cache-Control : https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cache-Control

 
 

【Azure 存储服务】访问Azure Blob File遇见400-Condition Headers not support错误的解决之路的更多相关文章

  1. 【Azure 存储服务】代码版 Azure Storage Blob 生成 SAS (Shared Access Signature: 共享访问签名)

    问题描述 在使用Azure存储服务,为了有效的保护Storage的Access Keys.可以使用另一种授权方式访问资源(Shared Access Signature: 共享访问签名), 它的好处可 ...

  2. 【Azure 存储服务】.NET7.0 示例代码之上传大文件到Azure Storage Blob

    问题描述 在使用Azure的存储服务时候,如果上传的文件大于了100MB, 1GB的情况下,如何上传呢? 问题解答 使用Azure存储服务时,如果要上传文件到Azure Blob,有很多种工具可以实现 ...

  3. 玩转Windows Azure存储服务——网盘

    存储服务是除了计算服务之外最重要的云服务之一.说到云存储,大家可以想到很多产品,例如:AWS S3,Google Drive,百度云盘...而在Windows Azure中,存储服务却是在默默无闻的工 ...

  4. 解读 Windows Azure 存储服务的账单 – 带宽、事务数量,以及容量

    经常有人询问我们,如何估算 Windows Azure 存储服务的成本,以便了解如何更好地构建一个经济有效的应用程序.本文我们将从带宽.事务数量,以及容量这三种存储成本的角度探讨这一问题. 在使用 W ...

  5. 【Azure 存储服务】Java Azure Storage SDK V12使用Endpoint连接Blob Service遇见 The Azure Storage endpoint url is malformed

    问题描述 使用Azure Storage Account的共享访问签名(Share Access Signature) 生成的终结点,连接时遇见  The Azure Storage endpoint ...

  6. azure跨域问题(访问azure存储账户数据,blob)

    访问azure存储账户数据报错:405错误 解决方案 打开访问的存储账户--->CORS--->Blob服务 全部填写*就可以了,点击“保存”即可. iframe就可以展示blob中的pd ...

  7. 【Azure 存储服务】Hadoop集群中使用ADLS(Azure Data Lake Storage)过程中遇见执行PUT操作报错

    问题描述 在Hadoop集中中,使用ADLS 作为数据源,在执行PUT操作(上传文件到ADLS中),遇见 400错误[put: Operation failed: "An HTTP head ...

  8. 玩转Windows Azure存储服务——高级存储

    在上一篇我们把Windows Azure的存储服务用作网盘,本篇我们继续挖掘Windows Azure的存储服务——高级存储.高级存储自然要比普通存储高大上的,因为高级存储是SSD存储!其吞吐量和IO ...

  9. 【Azure 存储服务】Python模块(azure.cosmosdb.table)直接对表存储(Storage Account Table)做操作示例

    什么是表存储 Azure 表存储是一项用于在云中存储结构化 NoSQL 数据的服务,通过无结构化的设计提供键/属性存储. 因为表存储无固定的数据结构要求,因此可以很容易地随着应用程序需求的发展使数据适 ...

  10. 【Azure 云服务】Azure Cloud Service在发布新部署后遇见不能RDP(远程连接)到实例时如何处理?

    Azure 云服务是PaaS 的一个示例. 与 Azure 应用服务一样,此技术设计用于支持可缩放.可靠且运营成本低廉的应用程序. 同样,应用服务托管在虚拟机 (VM) 上,Azure 云服务也是如此 ...

随机推荐

  1. 3、数据库:Oracle部署 - 系统部署系列文章

    Oracle数据库的安装,以前写过一篇,这次将新版的安装再记录一次,让读者能够有所了解,笔者也能够记录下最新版的安装过程. 一.数据库下载: Oracle最新版目前在官网是19c,从下面这个链接进去下 ...

  2. 【Python&GIS】判断图片中心点/经纬度点是否在某个面内

     Python的exifread库可以获取图片中的源数据信息,包括经纬度.相机厂商.曝光时间.焦距.拍摄时间.拍摄地点等等信息.我们可以通过exifread库从图片中获取图片的经纬度,再通过shape ...

  3. ChatGPT之问艺道:如何借助神级算法Prompt,让你轻松get到更高质量答案?

    摘要:本文由葡萄城技术团队编写,文章的内容借鉴于Ibrahim John的<The Art of Asking ChatGPT>(向ChatGPT提问的艺术). 前言 当今,ChatGPT ...

  4. RabbitMQ快速使用代码手册

    本篇博客的内容为RabbitMQ在开发过程中的快速上手使用,侧重于代码部分,几乎没有相关概念的介绍,相关概念请参考以下csdn博客,两篇都是我找的精华帖,供大家学习.本篇博客也持续更新~~~ 内容代码 ...

  5. Burp+Xray的联动使用

    Burp+Xray的联动使用 步骤如下, 1)首先,我们启动Xray的url监听功能,我们设置监听地址为127.0.0.1,端口为7777.监听的报告输出到xray文件夹根目录下的proxy_test ...

  6. 磐舟磐基平台:基于KubeEdge的落地实践

    摘要:实现统一管理.简化多集群的运维系统.减少运营成本:同时也成功将前面提到的500台鲲鹏服务器以及它上面的BC Linux for Euler集群纳入磐基PaaS平台的大家庭之中,运维效率大幅增加. ...

  7. 【后端面经-Java】AQS详解

    目录 1. AQS是什么? 2. AQS核心思想 2.1 基本框架 2.1.1 资源state 2.1.2 CLH双向队列 2.2 AQS模板 3. 源码分析 3.1 acquire(int) 3.1 ...

  8. java.lang.Error: Unresolved compilation problems

    一般有两种常见的情况: 1.当一个 jar 文件的 MANIFEST.MF 中已经标记了 Sealed: true 时,这个 jar 内所有的 java package 中的类必须来自这个 jar 包 ...

  9. java.lang.IndexOutOfBoundsException

    原因:一个ArrayList数组中没有元素,而你想获取第一个元素,运行是就会报此类型的错误 解决方案:用 array[] 的  .length 查看 数组的长度

  10. 实例讲解看nsenter带你“上帝视角”看网络

    摘要:本文重点关注进入目标进程的"网络ns"视角,即站在「容器中的进程视角」看待容器里面的网络世界,并在那个视角中执行命令. 本文分享自华为云社区<<跟唐老师学习云网络 ...