Azure功能应用程序 - 写入blob

时间:2018-03-28 05:24:22

标签: c# azure azure-storage-blobs azure-functions

我正在尝试从Azure函数写入blob(txt文件),但是,没有任何反应:没有创建blob,也没有抛出异常。 我从这里获取了Blob触发器代码:https://docs.microsoft.com/en-us/azure/azure-functions/functions-bindings-storage-blob#output

这是我的代码:

[FunctionName("ProcessFiles")]
public static void Run(
[BlobTrigger("sample-items/sample-file.csv", Connection = "sample-connection")] Stream myBlob,
[Blob("sample-items/validationResult.json", FileAccess.Write)] Stream validationOutput,
TraceWriter log)
{
    log.Info($"C# Blob trigger function Processed blob\n Size: {myBlob.Length} Bytes");

    using (var sw = new StreamWriter(validationOutput, Encoding.UTF8))
    {
        try
        {
            sw.Write("HELLO WORLD");            
            sw.Flush();
        }
        catch (Exception ex)
        {

        }
    }
}

这些是我的Nuget包:Microsoft.NET.Sdk.Functions 1.0.10。

blob容器具有“私人访问”政策

1 个答案:

答案 0 :(得分:2)

似乎我使用的流不正确。以下代码更改使其工作:(将Connection属性添加到validationOutput并从Stream更改为TextWriter)

[FunctionName("ProcessFiles")]
public static void Run(
[BlobTrigger("sample-items/sample-file.csv", Connection = "sample-connection")] Stream myBlob,
[Blob("sample-items/validationResult.json", FileAccess.Write, Connection = "sample-connection")] TextWriter validationOutput,
TraceWriter log)
{
    log.Info($"C# Blob trigger function Processed blob\n Size: {myBlob.Length} Bytes");

    validationOutput.WriteLine("hello world");
}