2
votes

I'm using the Azure Blob Storage node library: https://github.com/Azure/azure-storage-node

I've referred to this documentation: https://github.com/Azure/azure-content/blob/master/articles/storage-nodejs-how-to-use-blob-storage.md

I can do most blob operations just fine, but I'd like to list blobs that haven't been modified in a week. The documentation is pretty light but there appears to be an access condition I can use, I'm just not sure of the syntax. Here was my best guess:

var weekOld = new Date();
weekOld.setDate(weekOld.getDate() - 7);

var options = {accessConditions:{}};
options['accessConditions'][azure.BlobUtilities.AccessConditions.DATE_UNMODIFIED_SINCE] = weekOld;

blobSvc.listBlobsSegmentedWithPrefix('mycontainer', 'myprefix', null /*token*/, options, function(error, result, response){
    if(!error){
        result.entries.forEach(function(val, index, array){
            console.log(val.name);
            console.log(val.properties);
        });
    }
    console.log(response);
});

This pulls in all the blobs with the right prefix but ignores the modification date. I'm taking a guess at the syntax of passing in accessConditions with my query so it's not surprising this isn't working. Any help is much appreciated.

1
weekOld.setDate(weekOld.getDate() + 7); sets the date to a week in the future, not a week in the past. Do you mean weekOld.setDate(weekOld.getDate() - 7); instead?Trott
@Trott, good catch. I had changed it to plus seven for testing purposes but, in either case, it doesn't work.Yaron

1 Answers

3
votes

It is not possible to have server side filtering on the blobs using access conditions while listing blobs because List Blobs REST API operation doesn't support conditional headers. For the operations supporting conditional headers, please see Specifying Conditional Headers for Blob Service Operations (Section titled: Operations Supporting Conditional Headers).

Your best option would be to list the blobs and then do the filtering on the client side.