3
votes

I would like to fetch all the folder and files in a azure container in nodejs

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

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
There are no folders in any cloud BLOB storage provider. Definitely not Amazon, Azure, Rackspace, Openstack. ALL of them provide flat storage, with specific characters, typically / used as placeholders to simulate folders. Depending on the provider, you can request all files starting with a certain prefix, equivalent to asking for all files in a folder - Panagiotis Kanavos
The reason for the flat storage is that folders require recursion and therefore can't scale to cloud storage - Panagiotis Kanavos
but auzre said that there are folders in side the container and i gave path format as well "ios_06cd82e4db0845b9bef73c5b22bea2fa/Event/2016-09-29/18/" - Navneet Garg
So if I understand correctly, you wish to specify ios-analytics-full/ios_06cd82e4db0845b9bef73c5b22bea2fa/Event/{date e.g. 2016-09-29} and see the list of all blobs there. Correct? - Gaurav Mantri
yes analytics dumped in container every day and i want to read that data - Navneet Garg

1 Answers

2
votes

The function you would want to use is 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.

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);
    }
});