繁体   English   中英

我们可以在运行时在 Azure blob 存储中的 Container 下创建文件夹吗?

[英]Can we Create folders under Container at run time in Azure blob storage?

我在 typescript 中有以下代码。 用于将本地文件上传到给定容器中的 Azure blob 存储。 我们是否可以每次在该容器中创建一个文件夹,每当上传发生并且文件应该上传到容器中的该文件夹时。

路径:存储帐户-容器-文件夹-文件。

const STORAGE_ACCOUNT_NAME = "*******";
    const ACCOUNT_ACCESS_KEY = "************************";

    
  const containerName = "container1";
  const localFilePath = "../tree2.jpg";

  const credentials = new StorageSharedKeyCredential(STORAGE_ACCOUNT_NAME, ACCOUNT_ACCESS_KEY);

  const blobServiceClient = new BlobServiceClient(`https://${STORAGE_ACCOUNT_NAME}.blob.core.windows.net`,credentials);

  const containerClient = blobServiceClient.getContainerClient(containerName);
  
   const fileName = path.basename(localFilePath);
   const blobClient = containerClient.getBlobClient(fileName);
   const blockBlobClient = blobClient.getBlockBlobClient();
    blockBlobClient.uploadFile(localFilePath);

也许您可以尝试使用此代码:

const blobClient = containerClient.getBlobClient("foldername/fileName");

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM