gpt4 book ai didi

c# - Azure函数应用程序blob触发器无法上传文件

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

我创建了一个 blob 触发器,它接受 blob 中的文件,将其解压缩并使用流将其移动到另一个 blob。

我的代码如下所示

[FunctionName("Requests")]
[StorageAccount("samplecontainer")]
public static void Run([BlobTrigger("incoming/{name}")]Stream myBlob,
[Blob("processing/{name}.xml", FileAccess.Write)] TextWriter output,
string name, ILogger log)
{
log.LogInformation($"C# Blob trigger function Processed blob\n Name:{name} \n Size: {myBlob.Length} Bytes");
string returnValue;

using (Stream blob = myBlob)
{
using (GZipStream decompressionStream = new GZipStream(blob, CompressionMode.Decompress))
{
log.LogInformation($"Unzipping file");
name = name.Replace(".gz", "");
var content = String.Empty;
using (StreamReader reader = new StreamReader(decompressionStream))
{
content = reader.ReadToEnd();
reader.Close();

}
returnValue = content;
}
}
log.LogInformation($"C# Blob trigger function finished processing blob\n Name:{name} \n Now writing to xml");
output.WriteLine(returnValue);
}

实际上,在我的 local.settings.json 文件中使用“AzureWebJobsStorage”:“UseDevelopmentStorage=true”在本地运行它时,这将起作用。

但是,一旦我部署了此应用程序并使用 Azure 存储资源管理器将文件上传到真实容器,则没有任何反应,并且事件日志显示 Write.Tiny.txt.gz 中的操作失败,无法找到文件“D” :\home\site\wwwroot\Requests\tiny.txt.gz'。

我有可以工作的http触发器,并且我尝试关闭配置WEBSITE_RUN_FROM_PACKAGE但没有效果。我可能缺少一些设置或配置吗?当我在函数应用程序中控制台进入此路径并 cat function.json 时,我得到:

{
"generatedBy": "Microsoft.NET.Sdk.Functions-1.0.29",
"configurationSource": "attributes",
"bindings": [
{
"type": "blobTrigger",
"connection": "samplecontainer",
"path": "incoming/{name}",
"name": "myBlob"
}
],
"disabled": false,
"scriptFile": "../bin/azure-functions.dll",
"entryPoint": "Requests.Run"
}

最佳答案

好的,我可以重现您的问题。

既然你可以在本地工作,那么你的代码应该没有问题。

我可以解释为什么会发生这种情况。 Azure 上的函数应用没有可将数据写入 Azure Blob 存储的 RBAC。

以下步骤可以解决问题:

首先,创建函数应用的标识。

enter image description here

其次,将函数应用的 RBAC 角色添加到存储帐户。

enter image description here

顺便说一句,以上设置不会立即生效,需要等待几分钟才能生效。

关于c# - Azure函数应用程序blob触发器无法上传文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66534968/

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