繁体   English   中英

如何借助“azure-storage”Package 在 Azure Data Lake Storage Gen2 中的容器内创建文件夹

[英]How to create a folder inside container in Azure Data Lake Storage Gen2 with the help of 'azure-storage' Package

我使用 Azure Data Lake Gen2 作为我的存储。 在将文件上传到相关文件夹之前,我需要创建不同的文件夹结构。

我正在使用“Azure-Storage”javascript 库。 但我无法弄清楚如何通过这个库在容器内创建一个文件夹。

下面是连接到容器的代码。 我能够连接到容器并将文件上传到容器本身。

var azure = require('azure-storage'); //connecting to container
var blobService = azure.createBlobService("DefaultEndpointsProtocol=<>;EndpointSuffix=core.windows.net");
blobService.createContainerIfNotExists("pbitestdl2",{publicAccessLevel: 'blob'},(error, result, response) => {
    if (!error) {
        console.log('connected');
    }
});

在此处输入图像描述

如您所知,ADLS Gen2 的官方 SDK 现已不可用。

由于您正在为 ADLS Gen2 使用 Blob 存储 sdk,因此您应该知道以下几点:

在 azure blob 存储中,您需要知道一件事:blob 存储中没有“文件夹”,“文件夹”实际上是 blob 名称的一部分。 您不能在 Blob 存储中创建空文件夹。

当您为 ADLS Gen2 使用 blob 存储 SDK 时,您不能直接创建文件夹,您应该创建一个名称包含文件夹名称的 blob 文件,例如myfolder/my.txt

因此,当为 ADLS Gen2 使用 blob 存储 SDK 时,应使用以下代码:

var azure = require('azure-storage'); //connecting to container
var blobService = azure.createBlobService("DefaultEndpointsProtocol=xxx;EndpointSuffix=core.windows.net");
blobService.createContainerIfNotExists("pbitestdl2",{publicAccessLevel: 'blob'},(error, result, response) => {
    if (!error) {
        console.log('connected');
    }
});

blobService.createBlockBlobFromLocalFile('pbitestdl2', 'myfolder/my.txt', 'f:\\testfile.txt', function(error, result, response) {
    if (!error) {
      // file uploaded
      console.log('ok, uploaded');
    }
  });

然后你可以看到文件夹是在Azure Data Lake Gen2 storage中创建的,截图如下:

在此处输入图像描述

Another way , you can use ADLS Gen2 Path - Create rest api to directly create a folder, but you need to do a lot of work to build authentication token for the rest api.

这个示例对我有用,特别是:filesystem_client.create_directory(dir_name)

暂无
暂无

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

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