如何从天蓝色容器中获取文件夹列表?

时间:2017-05-31 13:19:29

标签: node.js azure azure-storage-blobs azure-application-insights

我想获取nodejs

中azure容器中的所有文件夹和文件

我正在使用azure-storage库获取blob,但无法找到列出容器下所有文件夹的任何示例。我正在将我的anaylitics数据转储(导出)到auzure的存储容器中。现在我试着阅读这些文件

我的存储结构如

ios-analytics-full/ios_06cd82e4db0845b9bef73c5b22bea2fa/Event/2016-09-29/18/270b58c-04d7-4e5d-a503-cdce24a3940c_20160929_184723.blob

我想阅读为每一天创建的所有文件夹以及这些文件夹下的文件

var containerName = "assist-ios-analytics-full";


blobService.listBlobsSegmented(containerName, null, {maxResults : 10}, function(err, result) {
    if (err) {
        console.log("Couldn't list blobs for container %s", containerName);
        console.error(err);
    } else {
        console.log('Successfully listed blobs for container %s', containerName);
        console.log(result.entries);
        console.log(result.continuationToken);
        res.json(result);
    }
});

最新文件夹将是今天的日期

ios-analytics-full/ios_06cd82e4db0845b9bef73c5b22bea2fa/Event/2017-05-31/18/270b58c-04d7-4e5d-a503-cdce24a3940c_20160929_184723.blob

1 个答案:

答案 0 :(得分:3)

您要使用的功能是listBlobsSegmentedWithPrefix

您要做的是将prefix指定为ios_06cd82e4db0845b9bef73c5b22bea2fa/Event/{date e.g. 2017-05-31},将options.delimiter指定为"",这将确保返回所有blob,其中name以上面的前缀开头。

所以你的代码将是:

blobService.listBlobsSegmentedWithPrefix(containerName, 'ios_06cd82e4db0845b9bef73c5b22bea2fa/Event/2017-05-31', null, {delimiter: "", maxResults : 10}, function(err, result) {
    if (err) {
        console.log("Couldn't list blobs for container %s", containerName);
        console.error(err);
    } else {
        console.log('Successfully listed blobs for container %s', containerName);
        console.log(result.entries);
        console.log(result.continuationToken);
        res.json(result);
    }
});