[英]How can I open a writeable stream to a new Blob using the new Azure Storage SDK v12?
I am using Azure Storage SDK v12 and I am looking for a way to open a stream to specific Blob, like in the previous versions:我正在使用 Azure 存储 SDK v12 并且我正在寻找一种方法来打开 stream 到特定 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())
{
....
}
The problem is that I do not find the OpenWrite
method in the new API that would get me access to a Stream
.问题是我在新的 API 中找不到
OpenWrite
方法,它可以让我访问Stream
。
Question问题
How can I open a writeable stream to a Blob using the new Azure Storage SDK v12?如何使用新的 Azure 存储 SDK v12 打开可写 ZF7B44CFFAFD5C52223D5498196C8A2E7BZ 到 Blob?
Workaround解决方法
Since I am working with Azure Functions, I have a workaround that involves using the Blob as Out parameter of my function:由于我正在使用 Azure 函数,因此我有一个解决方法,涉及使用 Blob 作为我的 function 的 Out 参数:
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.
}
You need to use GetBlockBlobClient extension method from the Azure.Storage.Blobs.Specialized namespace:您需要使用 Azure.Storage.Blobs.Specialized 命名空间中的 GetBlockBlobClient 扩展方法:
public async Task<Stream> CreateOutputStream(string fullFilePath)
{
var blockBlobClient = _blobContainerClient.GetBlockBlobClient(fullFilePath);
var stream = await blockBlobClient.OpenWriteAsync(true);
return stream;
}
Try this尝试这个
BlobContainerClient containerClient = await blobServiceClient.CreateBlobContainerAsync("zipfiles");
BlobClient blobClient = containerClient.GetBlobClient(Guid.NewGuid().ToString());
using(FileStream strem = File.OpenRead("10_million_lines.file")){
await blobClient.UploadAsync(strem , true);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.