【问题标题】:How to get file metadata from Azure File Share?如何从 Azure 文件共享中获取文件元数据?
【发布时间】:2020-12-28 13:32:56
【问题描述】:

我正在尝试使用 npm storage-file-share 从 Azure 文件共享中获取文件共享元数据。

代码 sn-p 如下,但在文档中没有找到任何获取元数据的地方。

有什么方法可以从 azure 库中获取元数据或必须调用 rest api

const serviceClient = new ShareServiceClient(
      `https://${storageAccountName}.file.core.windows.net`,
      credential
    );
    const directoryClient  = serviceClient.getShareClient(shareName).getDirectoryClient(directoryPath);
    const dirIter = directoryClient.listFilesAndDirectories();
    const list = [];
    for await (const item of dirIter) {
        list.push({name: item.name, metadata????}); // Need item metadata 
    }

【问题讨论】:

    标签: javascript node.js azure azure-storage storage-file-share


    【解决方案1】:

    您可以将getProperties 方法用于fetching metadata 用于filedirectory。下面是这个方法的定义:

    返回所有用户定义的元数据、标准 HTTP 属性和 文件的系统属性。它不返回的内容 文件。

    所以在你的代码中 -> 在for await (const item of dirIter) 中,你需要确定它是file 还是directory,然后调用getProperties() 方法。示例代码如下所示:

    for await (const item of dirIter) {
          if (item.kind === "directory") {
            
            const mydirectory = directoryClient.getDirectoryClient(item.name);
            var diretory_properties = await mydirectory.getProperties();
    
            //for test, you can print out the metadata
            console.log(diretory_properties.metadata);
    
            //here, you can write code to add the metadata in your list
    
          } else {
            
            const myfile=directoryClient.getFileClient(item.name);
            var the_properties = await myfile.getProperties();
    
            //for test, you can print out the metadata
            console.log(the_properties.metadata)
    
           //here, you can write code to add the metadata in your list
    
          }
        }
    

    【讨论】:

      【解决方案2】:

      可以使用getShareMetadata的方法

      fileService.getShareMetadata(shareName, function (error, result, response) {
      

      【讨论】:

        猜你喜欢
        • 2020-11-06
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2019-08-17
        • 2020-10-07
        • 2022-06-30
        • 2016-07-03
        相关资源
        最近更新 更多