我想获取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
答案 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);
}
});