簡體   English   中英

將 Azure blob 文件上傳到存儲帳戶容器中的嵌套文件夾

[英]Upload Azure blob file to nested folders in storage account container

我正在嘗試將 azure blob 文件上傳到嵌套文件夾結構中,如下所示:

Blob 存儲快照

能夠成功地將文件上傳到父容器,即“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”,但這不起作用。

請建議和指導我。

嘗試更改以下代碼行:

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

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM