如何使用新的Azure Storage SDK V12将可写流打开到新Blob?

How can I open a writeable stream to a new Blob using the new Azure Storage SDK v12?(如何使用新的Azure Storage SDK V12将可写流打开到新Blob?)
本文介绍了如何使用新的Azure Storage SDK V12将可写流打开到新Blob?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Azure Storage SDK V12,我正在寻找一种方法来打开指向特定Blob的流,就像以前的版本一样:

CloudBlobClient cloudBlobClient = account.CreateCloudBlobClient();

CloudBlobContainer container = cloudBlobClient.GetContainerReference("zipfiles");

var blob = container.GetBlockBlobReference(Guid.NewGuid().ToString());

// Here is the the functionality I am looking for: OpenWrite that returns a Stream.
using (Stream blobStream = blob.OpenWrite())
{
  ....
}

问题是我在新API中找不到可以让我访问StreamOpenWrite方法。

问题

如何使用新的Azure Storage SDK V12将可写流打开到Blob?


解决办法

因为我使用的是Azure函数,所以我有一个解决办法,涉及将Blob用作函数的输出参数:

public async Task RunAsync(
            [BlobTrigger("data/{listId}/{name}.txt", Connection = "storageAccountConnectionString")]
            Stream sourceStream,
            string listId,
            string name,
            [Blob("data/{listId}/processed/{name}.txt", FileAccess.Write, Connection = "storageAccountConnectionString")] 
            Stream destinationStream)
{
    //  Here I use the destinationStream instance to upload data as it is being processed. It prevents me from loading everything in memory before calling the UploadAsync method of a BlobClient instance.
}

推荐答案

您需要使用Azure.Storage.Blobs.Specialized Nampase:

中的GetBlockBlobClient扩展方法
public async Task<Stream> CreateOutputStream(string fullFilePath)
{
    var blockBlobClient = _blobContainerClient.GetBlockBlobClient(fullFilePath);
    var stream = await blockBlobClient.OpenWriteAsync(true);

    return stream;
}

这篇关于如何使用新的Azure Storage SDK V12将可写流打开到新Blob?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

DispatcherQueue null when trying to update Ui property in ViewModel(尝试更新ViewModel中的Ui属性时DispatcherQueue为空)
Drawing over all windows on multiple monitors(在多个监视器上绘制所有窗口)
Programmatically show the desktop(以编程方式显示桌面)
c# Generic Setlt;Tgt; implementation to access objects by type(按类型访问对象的C#泛型集实现)
InvalidOperationException When using Context Injection in ASP.Net Core(在ASP.NET核心中使用上下文注入时发生InvalidOperationException)
LINQ many-to-many relationship, how to write a correct WHERE clause?(LINQ多对多关系,如何写一个正确的WHERE子句?)