简体   繁体   English

如何使用新的 Azure 存储 SDK v12 打开可写 ZF7B44CFFAFD5C52223D5498196C8A2E7BZ 到新 Blob?

[英]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.

相关问题 如何使用 Azure.Storage v12 SDK 从 Azure Blob 中删除元数据? - How can I remove metadata from an Azure Blob using Azure.Storage v12 SDK? 如何使用 .NET v12 SDK 在 Azure Blob 存储中使用指定的 ContentType 上传 Blob? - How upload blob in Azure Blob Storage with specified ContentType with .NET v12 SDK? Azure Blob 存储使用 Key Vault.Net v12 解密 SDK - Azure Blob Storage Decrypt Using Key Vault .Net v12 SDK 如何使用最新的 Azure SDK .NET API v12 在 Blob 上获取共享访问签名? - How to get a Shared Access Signature on a Blob using the latest Azure SDK .NET API v12? 使用指定的 ContentType 将 blob 上传到 Azure Blob 存储并同时覆盖(.NET v12 SDK)? - Upload blob into Azure Blob Storage with specified ContentType and overwrite same time (.NET v12 SDK)? Azure Blob 存储客户端库 v12 设置代理 - Azure Blob Storage client library v12 setting proxy ContentHash 未在 Azure Blob Storage v12 中计算 - ContentHash not calculated in Azure Blob Storage v12 Azure blob 存储 V12 - 使用专用类 BlockBlobStorage 的示例 - Azure blob storage V12 - Example of using specialized class BlockBlobStorage 使用适用于 .Net 的 Azure Bob Storage v12 SDK 进行加密 - Encryption with Azure Bob Storage v12 SDK for .Net 上传大文件 Azure Blob .net SDK v12 问题 - Upload Larget File Azure Blob .net SDK v12 Problem
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM