0

I have file which was stored in some Azure blob directory "folder1/folder2/file.txt". This file was soft deleted - I can see it in Azure web console. I need to have function which checks this file existence.

  1. I tried library "azure-storage". It perfectly works with NOT removed files:
const blobService = azure.createBlobService(connectingString);
blobService.doesBlobExist(container, blobPath, callback) 

May be anyone knows how use same approach with soft removed files?

  1. I tied with lib "@azure/storage-blob". But I stuck with endless entities there (BlobServiceClient, ContainerItem, BlobClient, ContainerClient, etc) and couldn't find way to see particular file in particular blob directory.
0

1 Answer 1

0

Following this MSDOC, I got to restore the Soft deleted blobs and their names with the below code snippet.

const { BlobServiceClient } = require('@azure/storage-blob');
const  connstring = "DefaultEndpointsProtocol=https;AccountName=kvpstorageaccount;AccountKey=<Storage_Account_Key>;EndpointSuffix=core.windows.net"

if (!connstring) throw  Error('Azure Storage Connection string not found');
const  blobServiceClient = BlobServiceClient.fromConnectionString(connstring);

async  function  main(){
const  containerName = 'kpjohncontainer';
const  blobName = 'TextFile05.txt';
const  containerClient = blobServiceClient.getContainerClient(containerName);
undeleteBlob(containerClient, blobName)

}

main()
.then(() =>  console.log(`done`))
.catch((ex) =>  console.log(ex.message));

async  function  undeleteBlob(containerClient, blobName){

const  blockBlobClient = await  containerClient.getBlockBlobClient(blobName);
await  blockBlobClient.undelete(); //to restore the deleted blob

console.log(`undeleted blob ${blobName}`);
}

Output:

enter image description here

To check if the blob exists and if exists but in Soft-deleted state, I found the relevant code but it’s in C# provided by @Gaurav Mantri. To achieve the same in NodeJS refer here.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.