使用Dapr Azure Blob Storage绑定时遭遇容器不存在错误
解决Dapr Azure Blob Storage绑定中「容器不存在」的问题
从错误日志的请求URL可以明确问题:
PUT https://ifmsstorageaccount.blob.core.windows.net/ifmsstorageaccount/default/ifms-filestore/...
Dapr尝试访问的容器是ifmsstorageaccount/default/ifms-filestore,但你实际创建的容器名是ifms-filestore,问题出在Bicep配置传递给Dapr组件的容器名错误。
问题根源
在storage-account.bicep里,你输出的storageAccountContainerName是容器的完整资源相对名称(格式为${storageAccount.name}/default/${containerName}),但Dapr的Azure Blob Storage绑定只需要单纯的容器名,不需要存储账户和blob服务的前缀。
解决方案
修改storage-account.bicep的输出,直接输出容器名变量containerName,而非容器资源的名称:
@description('The location in which the Azure Storage resources should be deployed.') param location string @description('The name of the blob container.') var containerName = 'ifms-filestore' resource storageAccount 'Microsoft.Storage/storageAccounts@2022-05-01' = { name: 'ifmsstorageaccount' location: location sku: { name: 'Standard_LRS' } kind: 'BlobStorage' properties: { accessTier: 'Hot' } } resource container 'Microsoft.Storage/storageAccounts/blobServices/containers@2022-05-01' = { name: '${storageAccount.name}/default/${containerName}' } output storageAccountId string = storageAccount.id output storageAccountApiVersion string = storageAccount.apiVersion output storageAccountName string = storageAccount.name // 修改此处:直接输出容器名变量,而非容器资源的完整名称 output storageAccountContainerName string = containerName
后续步骤
- 重新部署
storage-account.bicep,确保输出的容器名正确 - 重新部署
blobstorage.bicep,让Dapr组件获取到正确的容器名
修改后,Dapr会使用正确的容器名ifms-filestore发起请求,URL会变为https://ifmsstorageaccount.blob.core.windows.net/ifms-filestore/...,就能匹配你在Azure门户中创建的容器了。
内容的提问来源于stack exchange,提问作者Makhele Sabata
相关产品推荐
相关产品推荐

