4
votes

I am storing image files as blobs in Azure Storage with the following naming convention:

directory/image-name

When trying to retrieve the blobs using BlobService.listBlobs(container, options, callback) in Javascript on the server, I use:

var options = { "prefix":directory }

and it gets back only blobs that start with the directory name, as I expect, but I thought I would also be able to use:

var options = { "delimiter":"/", "prefix":directory }

and get back the same blobs, perhaps without the prefix in their names. Instead I get back nothing at all. What is the correct way to use the delimiter? What's the point in having it if you get the items that you want with only using the prefix?

1
Am I correct in understanding that you're using node.js? - Gaurav Mantri

1 Answers

6
votes

I've not used the REST APIs from JavaScript, but I think what you are missing is a trailing slash after the directory name, so I suggest:

var options = { "delimiter":"/", "prefix":directory+"/" }

Windows Azure Storage doesn't really have directories, in the underlying implementation all the blobs in a container are just flat list, and blob names (not container names) may contain slashes. The delimiter is an option when calling the ListBlobs REST API that allows you to simulate directory-like behavior. If the delimiter option is enabled, and the part of the blob name past the prefix contains the delimiter, the reply will omit that blob.

To illustrate, lets name some blobs, assuming all of them in the same container https://myaccount.blob.core.windows.net/mycontainer":

a/b/extra.txt
a/bloba.txt
a/blobb.txt
other.txt

So then if you invoke listBlobs on that container with the prefix "a/" and without specifying the delimiter, it will return the first three names, because they all have the "a/" prefix.

If instead you invoke listBlobs with the same "a/" prefix and set the delimiter to "/", you only get the middle two names; the service leaves out a/b/extra.txt because it's in a (simulated) sub-directory "b".