将Azure Blob文件上载到存储帐户容器中的嵌套文件夹

nkkqxpd9  于 2022-12-04  发布在  其他
关注(0)|答案(1)|浏览(169)

我正在尝试将azure blob文件上载到嵌套文件夹结构,如下所示:
Blob Storage snapshot
能够成功地上传文件到父容器,这是“testblobupload”。
下面是我的代码,可能看起来很大的块,真的很抱歉:

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);
        }

我尝试将容器名称更改为“testblobupload/TransactionalData/BACKTRACK”,但不起作用。
请给我建议和指导。

zf9nrax1

zf9nrax11#

尝试更改以下代码行:

BlobClient blobClient = containerClient.GetBlobClient($"{$"{DateTime.UtcNow:yyyyMMdd}"}/{fileName}");

BlobClient blobClient = containerClient.GetBlobClient($"TransactionalData/BACKTRACK/{DateTime.UtcNow:yyyyMMdd}/{fileName}");

相关问题