首页 > 其他分享 >【Azure 存储服务】访问Azure Blob File遇见400-Condition Headers not support错误的解决之路

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

时间:2023-10-27 15:33:51浏览次数:48  
标签:account name headers support no storage Headers file Azure

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

问题描述

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

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

【Azure 存储服务】访问Azure Blob File遇见400-Condition Headers not support错误的解决之路_Storage

错误消息为:

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) 为参考,找到了问题的根源

【Azure 存储服务】访问Azure Blob File遇见400-Condition Headers not support错误的解决之路_属性值_02

 

根源

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】进行修改。

【Azure 存储服务】访问Azure Blob File遇见400-Condition Headers not support错误的解决之路_Storage_03

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

【Azure 存储服务】访问Azure Blob File遇见400-Condition Headers not support错误的解决之路_Storage_04

(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 ... "

 

执行结果展示动画:

【Azure 存储服务】访问Azure Blob File遇见400-Condition Headers not support错误的解决之路_Azure_05

 

 

参考资料

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

 

 

 

当在复杂的环境中面临问题,格物之道需:浊而静之徐清,安以动之徐生。 云中,恰是如此!



标签:account,name,headers,support,no,storage,Headers,file,Azure
From: https://blog.51cto.com/u_13773780/8058307

相关文章

  • 【Azure Storage Account Table】询问批量将存储账户中的表嵌入另一个账户中的办法
    问题描述询问批量将存储账户中的表嵌入另一个账户中的办法? 问题解答方式一:使用 AzCopy 使用Azcopy做表格的导入导出,注意您需要使用Azcopy7.3版本来实现对Table的操作,可以选择导出到Blob中,这样导出的数据不会保存在本地,以及该指定支持并发导出。从表存储导出数据: https://le......
  • 【Azure Batch】在中国区批处理服务(Mooncake Batch Account)上实验自动池(Auto Pool)
    问题描述在AzureBatch的介绍文档中,提出了自动池的概念,它可以在任务完成后,自动删除Pool资源,详细介绍:https://docs.azure.cn/zh-cn/batch/nodes-and-pools#autopools& https://learn.microsoft.com/zh-cn/rest/api/batchservice/job/add?tabs=HTTP#autopoolspecification自动池是......
  • Azure DevOps 发布.Net项目到Windows IIS站点之pubxml
    通过VS中我们配置的pubxml进行发布trigger:-masterpool:vmImage:'windows-2022'variables:-group:GeexPublish-name:my-user-variablevalue:$[variables.UserName]#usesruntimeexpression-name:my-passed-variablevalue:$[variables.PassWord]......
  • Table does not support optimize, doing recreate + analyze instead
    使用情况:当您的库中删除了大量的数据后,您可能会发现数据文件尺寸并没有减小。这是因为删除操作后在数据文件中留下碎片所致。OPTIMIZETABLE只对MyISAM,BDB和InnoDB表起作用。对于BDB表,OPTIMIZETABLE目前被映射到ANALYZETABLE上。对于InnoDB表,OPTIMIZETABLE被映射到ALTER......
  • 【Azure Logic App】消费型逻辑应用在消费Service Bus时遇见消息并发速度慢,消息积压
    问题描述消费型逻辑应用(ConsumptionLogicApp)使用触发器模式消费AzureServiceBus的消息,当ServiceBus中存在大量消息等待消费时,LogicApp消费速度太慢,并发数无法满足需求。造成消息积压,有什么办法可以优化吗? 问题解答在LogicApp的配置中,可以修改“更改触发器并发”来......
  • 【Azure App Service】App Service设置访问限制后,使用git clone代码库出现403报错
    问题描述在AppService中,为AppService配置了访问限制,结果导致在克隆AppService的代码时候,遇见403错误。  问题解答因为在使用gitcloneAppService的应用代码时,使用的URL地址为https://***.scm.chinacloudsites.cn/***.git,它是通过公网访问,并且会根据设定的访问限制......
  • TLS Handshake failed: tls: server selected unsupported protocol version 301
    2023/10/2321:04:55D:/Dev/sre/gormSQLServer/main.go:20[error]failedtoinitializedatabase,goterrorTLSHandshakefailed:tls:serverselectedunsupportedprotocolversion301TLSHandshakefailed:tls:serverselectedunsupportedprotocolversion30......
  • The JSON value of length n is too large and not supported
    https://github.com/dotnet/runtime/issues/39953 I'mreferringtothisissue #30746 thatwasclosedwithlimitof125MBstayingfixedopposedtobeingconfigurable.Itwasarguedthattherewouldbenocommoncaseshittingthe125MBlimit.Suchcases......
  • [Microsoft Azure] Azure Function 如何重命名函数
    在开始之前,我们先了解一下AzureFunction的基本概念。AzureFunctions是MicrosoftAzure提供的一项无服务器计算服务,允许用户在云端运行代码而无需关心底层基础设施。通过使用AzureFunctions,您可以专注于编写业务逻辑,而无需担心服务器的管理和扩展。现在,让我们看看如何重命名Azu......
  • [Microsoft Azure] 如何查看 Azure Function的.NET SDK版本列表
    本文将介绍如何在MicrosoftAzure中查看和选择AzureFunction的.NETSDK版本列表,以便为您的项目选择合适的版本。在MicrosoftAzure中,AzureFunctions是一种用于在云端运行小型应用程序或功能的服务。它可以帮助我们在不需要管理基础设施的情况下快速构建和部署应用程......