[英]Upload Azure blob file to nested folders in storage account container
I am trying to upload azure blob file to a nested folder structure as:我正在尝试将 azure blob 文件上传到嵌套文件夹结构中,如下所示:
Blob Storage snapshot Blob 存储快照
I was able to successfully upload the file to the parent container which is "testblobupload".我能够成功地将文件上传到父容器,即“testblobupload”。
Following is my code which might look huge block, really sorry:以下是我的代码,可能看起来很大,真的很抱歉:
var containerNameToUploadTheFile = applyConfirmPriceConfig.AzureBlobStorageContainerNameConfig; // Default container name where file will be saved.
//Azure Blob Storage Temp Storage Container
var connectionString = applyConfirmPriceConfig.AzureBlobStorageContainerConnectionString;
var serviceClient = new BlobServiceClient(connectionString);
containerClient = serviceClient.GetBlobContainerClient(containerNameToUploadTheFile);
var id = eventObject.Id;
var sbmessage = new ServiceBusMessage();
sbmessage.MessageId = eventObject.Id.ToString();
sbmessage.Subject = eventObject.GetType().Name.Replace(ServiceBusConstants.IntegrationEventSuffix, string.Empty).Trim();
BlobUploadOptions options = new BlobUploadOptions
{
TransferOptions = new StorageTransferOptions
{
// Set the maximum number of workers that
// may be used in a parallel transfer.
MaximumConcurrency = 20,
// Set the maximum length of a transfer to 5MB.
// Set the maximum length of a transfer to 262144 = 256KB. This is service bus message size in standard
MaximumTransferSize = 0x40000, //50 * 1024,// * 1024,
InitialTransferLength = 0x40000,
},
HttpHeaders = new BlobHttpHeaders { ContentType = "application/json" }
};
fileName = $"{$"{DateTime.UtcNow:yyyyMMddHHMM}"}_{sbmessage.Subject}_{sbmessage.MessageId}";
var memorystream = new MemoryStream(Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(eventObject)));
BlobClient blobClient = containerClient.GetBlobClient($"{$"{DateTime.UtcNow:yyyyMMdd}"}/{fileName}");
await blobClient.UploadAsync(memorystream, options);
}
I tried changing the container name to "testblobupload/TransactionalData/BACKTRACK" but that doesn't work.我尝试将容器名称更改为“testblobupload/TransactionalData/BACKTRACK”,但这不起作用。
Please suggest and guide me.请建议和指导我。
Try by changing the following line of code:尝试更改以下代码行:
BlobClient blobClient = containerClient.GetBlobClient($"{$"{DateTime.UtcNow:yyyyMMdd}"}/{fileName}");
to到
BlobClient blobClient = containerClient.GetBlobClient($"TransactionalData/BACKTRACK/{DateTime.UtcNow:yyyyMMdd}/{fileName}");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.