Reputation: 201
Beginning a nodejs project, I need to retrieve the latest snapshot (and its metadata) for a specific blob. I'm using the Azure Blob storage client library v12 for JavaScript.
I'm not sure but I only found a method linked to the ContainerClient permitting to list all the blobs and snapshot within the container. Imo it's not for me very efficient in term of performance.
Is there a way to directly get the latest snapshot of a known blob or at least get all the snapshots ?
//construct of the blob storage connection
const blobServiceClient = new BlobServiceClient(
`https://${account}.blob.core.windows.net/`,
sharedKeyCredential
);
//target application container
let containerClient = blobServiceClient.getContainerClient(app);
blobClient = containerClient.getBlobClient(filename); //ok
//blobSnapshots = containerClient.getSnapshots(filename); // nok
The method in the last commented line for sure doesnt exist but is there an equivalent method ?
Upvotes: 1
Views: 1034
Reputation: 136196
Is there a way to directly get the latest snapshot of a known blob
Unfortunately no. You will need to list all snapshots of a blob and sort them reverse chronologically based on snapshot date/time and pick the 1st blob. That would be the latest snapshot.
or at least get all the snapshots ?
You will need to call listBlobsFlat
method with the following options
:
prefix
: This should be the name of the blob.includeSnapshots
: Value of this parameter should be true.Upvotes: 4