Azure函数复制上传触发的文件



我正在尝试扩展基本教程,该教程允许您在文件上传到blob存储后记录信息。教程中的代码是有效的,并且是从这里提取的:

https://learn.microsoft.com/en-us/azure/azure-functions/functions-create-storage-blob-triggered-function

我现在正试图添加一个输出,将该文件复制到另一个容器中。我使用的是在这里的输出示例中找到的代码:

https://learn.microsoft.com/en-us/azure/azure-functions/functions-bindings-storage-blob-output?tabs=csharp#example

我的代码只是对原始示例的一个小的补充。

run.csx:

using System.IO;
using System.Collections.Generic;
using Microsoft.Azure.WebJobs;
public static void Run([BlobTrigger("samples-workitems/{name}")] Stream myBlob, [Blob("copytwotkelly/{name}", FileAccess.Write)] Stream duplicateUpload, string name, ILogger log)
{
log.LogInformation($"C# Blob trigger function Processed blobn Name:{name} n Size: {myBlob.Length} Bytes");
myBlob.CopyTo(duplicateUpload);
}

function.json:

{
"bindings": [
{
"name": "myBlob",
"type": "blobTrigger",
"direction": "in",
"path": "samples-workitems/{name}",
"connection": "AzureWebJobsStorage"
},
{
"name": "duplicateUpload",
"path": "copytwotkelly/{name}",
"connection": "AzureWebJobsStorage",
"direction": "out",
"type": "blob"
}
]
}

当功能触发时,我会收到错误消息:

2020-11-25T06:29:57.518[Error]run.csx(5,25(:Error CS0246:找不到类型或命名空间名称"BlobTriggerAttribute"(是否缺少using指令或程序集引用?(2020-11-25T06:29:57.580[Error]run.csx(5,25(:Error CS0246:找不到类型或命名空间名称"BlobTrigger"(是否缺少using指令或程序集引用?(2020-11-25T06:29:57.672[Error]run.csx(5,82(:Error CS0246:找不到类型或命名空间名称"BlobAttribute"(是否缺少using指令或程序集引用?(2020-11-25T06:29:57.729[Error]run.csx(5,82(:Error CS0246:找不到类型或命名空间名称"Blob"(是否缺少using指令或程序集引用?(

但据我所知,我已经正确地遵循了教程中的配置说明。它并没有在示例中显示.json文件,所以我不确定我做错了什么。我错过了什么?这些类不是它在使用Microsoft.Azure.WebJobs时所要求的吗;我提到的?提前感谢您的帮助。

下面的代码对我来说很好:

function.json

{
"bindings": [
{
"name": "myBlob",
"type": "blobTrigger",
"direction": "in",
"path": "test1/{name}",
"connection": "AzureWebJobsStorage"
},
{
"name": "myOutputBlob",
"type": "blob",
"path": "test2/{name}",
"connection": "AzureWebJobsStorage",
"direction": "out"
}
]
}

run.csx

public static void Run(Stream myBlob,Stream myOutputBlob, string name, ILogger log)
{
log.LogInformation($"C# Blob trigger function Processed blobn Name:{name} n Size: {myBlob.Length} Bytes");
myBlob.CopyTo(myOutputBlob);
}

这是官方文件:

https://learn.microsoft.com/en-us/azure/azure-functions/functions-bindings-storage-blob-output?tabs=csharp-脚本#示例

最新更新