gpt4 book ai didi

c# - Azure:指定的容器不存在,Dapr 与 ContainerApps

转载 作者:行者123 更新时间:2023-12-03 02:04:50 27 4
gpt4 key购买 nike

我正在使用 Dapr Azure Blob 存储绑定(bind)来设置文件存储

这是二头肌

存储帐户.bicep

@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 = container.name

blobstorage.bicep

param containerAppsEnvironmentName string
param storageAccountId string
param storageAccountApiVersion string
param storageAccountName string
param storageAccountContainerName string

resource containerAppsEnvironment 'Microsoft.App/managedEnvironments@2022-06-01-preview' existing = {
name: containerAppsEnvironmentName

resource daprComponent 'daprComponents@2022-03-01' = {
name: 'ifms-dapr-filestore'
properties: {
componentType: 'bindings.azure.blobstorage'
version: 'v1'
secrets: [
{
name: 'storage-account-account-key'
value: listKeys(storageAccountId, storageAccountApiVersion).keys[0].value
}
]
metadata: [
{
name: 'accountName'
value: storageAccountName
}
{
name: 'accountKey'
secretRef: 'storage-account-account-key'
}
{
name: 'containerName'
value: storageAccountContainerName
}
{
name: 'decodeBase64'
value: 'true'
}
]
scopes: [
'vehicle-management-web-api'
]
}
}
}

output daprPubSubName string = containerAppsEnvironment::daprComponent.name

AddFileAsync 是一个辅助函数,用于将文件添加到文件存储并使用 DaprtClinet 来执行此操作。

public async Task<FileReturnType> AddFileAsync(byte[] fileContent, string path, string fileName)
{
var filepath = Path.Combine(path, fileName);

string base64String = Convert.ToBase64String(fileContent, 0, fileContent.Length);
Dictionary<string, string> metadata = new Dictionary<string, string>{ {"blobName",filePath}};

await _daprClient.InvokeBindingAsync("ifms-dapr-filestore", "create", base64String, metadata);
long fileSize = fileContent.Length;
var extension = Path.GetExtension(fileName);

return new FileReturnType(filepath, fileSize, extension);
}

当我添加文件时,我收到以下错误消息

Dapr.DaprException: Binding operation failed: the Dapr endpoint indicated a failure. See InnerException for details.
---> Grpc.Core.RpcException: Status(StatusCode="Internal", Detail="error when invoke output binding ifms-dapr-filestore: error uploading az blob: -> github.com/Azure/azure-storage-blob-go/azblob.newStorageError, /home/vsts/work/1/go/pkg/mod/github.com/!azure/<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="f5948f808790d886819a87949290d897999a97d8929ab583c5dbc4c5dbc5" rel="noreferrer noopener nofollow">[email protected]</a>/azblob/zc_storage_error.go:42
===== RESPONSE ERROR (ServiceCode=ContainerNotFound) =====
Description=The specified container does not exist.
RequestId:d12aeaa8-301e-0019-71b3-2d46c2000000
Time:2023-01-21T16:12:42.7329062Z, Details:
Code: ContainerNotFound
PUT https://ifmsstorageaccount.blob.core.windows.net/ifmsstorageaccount/default/ifms-filestore/RequestLetters/REQ-DIH-MUN-002/REQ-DIH-MUN-002%20-%20Request%20Letter.pdf?timeout=61
Authorization: REDACTED
Content-Length: [958932]
User-Agent: [dapr-1.9.5-msft-1 Azure-Storage/0.10 (go1.19; linux)]
X-Ms-Blob-Cache-Control: []
X-Ms-Blob-Content-Disposition: []
X-Ms-Blob-Content-Encoding: []
X-Ms-Blob-Content-Language: []
X-Ms-Blob-Content-Type: []
X-Ms-Blob-Type: [BlockBlob]
X-Ms-Client-Request-Id: [184d2673-814b-45ea-7ad0-cfe8d1fca4b3]
X-Ms-Date: [Sat, 21 Jan 2023 16:12:42 GMT]
X-Ms-Meta-Contenttype: [application/grpc]
X-Ms-Meta-Daprauthority: [127.0.0.1:50001]
X-Ms-Meta-Daprgrpcacceptencoding: [identity,gzip,deflate]
X-Ms-Meta-Traceparent: [00-cbed618718a728703a987fd1f50b6b25-c3d612101f033c57-00]
X-Ms-Meta-Useragent: [grpc-dotnet/2.47.0 (.NET 7.0.2; CLR 7.0.2; net6.0; linux; x64) dapr-sdk-dotnet/v1.9.0+3224579c3e136020bbf713528965854ebbd4eefe]
X-Ms-Version: [2019-02-02]
--------------------------------------------------------------------------------
RESPONSE Status: 404 The specified container does not exist.
Content-Length: [225]
Content-Type: [application/xml]
Date: [Sat, 21 Jan 2023 16:12:42 GMT]
Server: [Windows-Azure-Blob/1.0 Microsoft-HTTPAPI/2.0]
X-Ms-Client-Request-Id: [184d2673-814b-45ea-7ad0-cfe8d1fca4b3]
X-Ms-Error-Code: [ContainerNotFound]
X-Ms-Request-Id: [d12aeaa8-301e-0019-71b3-2d46c2000000]
X-Ms-Version: [2019-02-02]

Azure 存储和容器均在 Azure 上配置,如下图所示 axure portal

最佳答案

我认为问题出在您的 storageAccountContainerName 中,查看错误响应似乎采用 {storageaccountName}/default/{actualContainerName} 的格式。

输出中 PUT 请求中的 URL 以 https://ifmsstorageaccount.blob.core.windows.net/ifmsstorageaccount/default/ifms-filestore/ 开头,格式为 https://{storageAccountName}.blob.core.windows.net/{storageAccountName}/default/{containerName}/{blobName} 而应该是 https://{storageAccountName}.blob .core.windows.net/{containerName}/{blobName}

尝试将 storageaccount.bicep 中的输出更改为:

output storageAccountContainerName string = last(split(container.name, '/'))

关于c# - Azure:指定的容器不存在,Dapr 与 ContainerApps,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/75194547/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com