简体   繁体   中英

why is the blob being created as empty?

Why is my blob being created without any content?

I have an output binding set to create a blob in the following:

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} ; 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?

Here's my implementation of the 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

You may want

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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