简体   繁体   English

为什么将Blob创建为空?

[英]why is the blob being created as empty?

Why is my blob being created without any content? 为什么创建的Blob没有任何内容?

I have an output binding set to create a blob in the following: 我有一个输出绑定集,用于在下面创建blob:

public static class OnSchedulingToMMMQueueTriggered
{
    [FunctionName("OnSchedulingToMMMQueueTriggered")]
    public static void Run(
        [QueueTrigger("httpqueue", Connection = "OnSchedulingToMMMQueueTriggered:SourceQueueConnection")] MyPayload myQueueItem,
        [Blob("processed/{Payload}", FileAccess.Write, Connection = "OnSchedulingToMMMQueueTriggered:ProcessedPayloadsConnectionString")] Stream processedPayload,
        ILogger log)
    {
        log.LogInformation($"C# Queue trigger function processed: {myQueueItem.Payload}");
        processedPayload = StreamGenerator.GenerateStreamFromString(myQueueItem.Payload);
    }
}

It creates a blob, and assigns it the correct naming with processed/{Payload} ; 它创建了一个Blob,并为它分配了正确的命名,并带有processed/{Payload} however, when I check to see what's inside the blob, it is empty! 但是,当我检查一下斑点内的内容时,它是空的!

I am assuming that this is not working: 我假设这不起作用:

        processedPayload = StreamGenerator.GenerateStreamFromString(myQueueItem.Payload);

The example I am following is this one, from here : 我要遵循的示例是此示例,从这里开始

[FunctionName("ResizeImage")]
    public static void Run(
    [BlobTrigger("sample-images/{name}")] Stream image,
    [Blob("sample-images-sm/{name}", FileAccess.Write)] Stream imageSmall, //output blob
    [Blob("sample-images-md/{name}", FileAccess.Write)] Stream imageMedium)
    {
         //your code here
    }

Why is the blob being created as empty? 为什么将Blob创建为空?

Here's my implementation of the StreamGenerator : 这是我的StreamGenerator实现:

public static class StreamGenerator
{
    public static Stream GenerateStreamFromString(string s)
    {
        var stream = new MemoryStream();
        var writer = new StreamWriter(stream);
        writer.Write(s);
        writer.Flush();
        stream.Position = 0;
        return stream;
    }
}

seems your code assign generated stream to a local var processedPayload 似乎您的代码将生成的流分配给本地var processedPayload

You may want 你可能想要

StreamGenerator.GenerateStreamFromString(myQueueItem.Payload).CopyTo(processedPayload)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM