为什么我创建的Blob没有任何内容?
我有一个输出绑定集,用于在下面创建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);
}
}
它创建一个blob,并用processed/{Payload}
为其分配正确的命名;但是,当我检查一下Blob中的内容时,它是空的!
我认为这不起作用:
processedPayload = StreamGenerator.GenerateStreamFromString(myQueueItem.Payload);
我要遵循的示例是来自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
}
为什么将Blob创建为空?
这是我对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;
}
}
答案 0 :(得分:1)
似乎您的代码将生成的流分配给本地变量processedPayload
您可能想要
StreamGenerator.GenerateStreamFromString(myQueueItem.Payload).CopyTo(processedPayload)