I would like to fetch all the folder and files in a azure container in nodejs
我想在nodejs的azure容器中获取所有文件夹和文件
I am using azure-storage library to get blob, but not able to find any example to list all the folder under a container. I am dumping (export) my anaylitics data to the storage container in auzure. Now i tried to read these files
我正在使用静态存储库来获取blob,但是找不到任何示例来列出容器下的所有文件夹。我正在向auzure的存储容器倾倒(输出)我的anaylitics数据。现在我试着读这些文件
My storage structure like
我的存储结构
ios-analytics-full/ios_06cd82e4db0845b9bef73c5b22bea2fa/Event/2016-09-29/18/270b58c-04d7-4e5d-a503-cdce24a3940c_20160929_184723.blob
I want to read all folder created for each day and files under these folders
我想要阅读每天创建的所有文件夹和这些文件夹下的文件
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);
}
});
latest folder would be today date
最新的文件夹将是今天的日期
ios-analytics-full/ios_06cd82e4db0845b9bef73c5b22bea2fa/Event/2017-05-31/18/270b58c-04d7-4e5d-a503-cdce24a3940c_20160929_184723.blob
1 个解决方案
#1
2
The function you would want to use is listBlobsSegmentedWithPrefix
.
您希望使用的函数是listBlobsSegmentedWithPrefix。
What you will do there is specify the prefix
as ios_06cd82e4db0845b9bef73c5b22bea2fa/Event/{date e.g. 2017-05-31}
and options.delimiter
as ""
which will ensure that all blobs are returned where name starts with the prefix above.
您要做的是将前缀指定为ios_06cd82e4db0845b9bef73c5b22bea2fa/Event/{date,例如2017-05-31}和options.delimiter指定为“”,这将确保在名称以上述前缀开头的地方返回所有blobs。
So your code will be:
所以你的代码是:
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);
}
});
#1
2
The function you would want to use is listBlobsSegmentedWithPrefix
.
您希望使用的函数是listBlobsSegmentedWithPrefix。
What you will do there is specify the prefix
as ios_06cd82e4db0845b9bef73c5b22bea2fa/Event/{date e.g. 2017-05-31}
and options.delimiter
as ""
which will ensure that all blobs are returned where name starts with the prefix above.
您要做的是将前缀指定为ios_06cd82e4db0845b9bef73c5b22bea2fa/Event/{date,例如2017-05-31}和options.delimiter指定为“”,这将确保在名称以上述前缀开头的地方返回所有blobs。
So your code will be:
所以你的代码是:
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);
}
});