本文介绍了如何使用新的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中找不到可以让我访问Stream
的OpenWrite
方法。
问题
如何使用新的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?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!