Node.js 检查NodeJS中的路径中是否存在blob

Node.js 检查NodeJS中的路径中是否存在blob,node.js,azure,azure-storage,azure-storage-blobs,Node.js,Azure,Azure Storage,Azure Storage Blobs,假设我想在一个容器中上传一个blob->azureblob 路径:123/human/a.json 我想检查路径:123/human/ 我找不到这方面的好资源 在c#中发现了这个 在节点上找不到任何内容如果您只想检查虚拟目录中是否存在任何blob,您可以在SDK中使用listBlobsSegmentedWithPrefix方法并尝试列出blob。如果得到的结果计数大于零,则表示目录中存在blob。例如,查看示例代码: blobService.listBlobsSegmentedWithPrefi

假设我想在一个容器中上传一个blob->
azureblob

路径:
123/human/a.json

我想检查路径:
123/human/

我找不到这方面的好资源

在c#中发现了这个


在节点上找不到任何内容

如果您只想检查虚拟目录中是否存在任何blob,您可以在SDK中使用
listBlobsSegmentedWithPrefix
方法并尝试列出blob。如果得到的结果计数大于零,则表示目录中存在blob。例如,查看示例代码:

blobService.listBlobsSegmentedWithPrefix('azureblob', '123/human/', null, {
  delimiter: '',
  maxReults: 1
}, function(error, result) {
  if (!error) {
    const entries = result.entries;
    if (entries.length > 0) {
      console.log('Blobs exist in directory...');
    } else {
      console.log('No blobs exist in directory...');
    }
  }
});
blobService.doesBlobExist('azureblob', '123/human/a.json', function(error, result) {
  if (!error) {
    if (result.exists) {
      console.log('Blob exists...');
    } else {
      console.log('Blob does not exist...');
    }
  }
});
如果您正在虚拟目录中查找特定blob的存在,只需使用SDK的
doesBlobExist
方法即可。例如,查看示例代码:

blobService.listBlobsSegmentedWithPrefix('azureblob', '123/human/', null, {
  delimiter: '',
  maxReults: 1
}, function(error, result) {
  if (!error) {
    const entries = result.entries;
    if (entries.length > 0) {
      console.log('Blobs exist in directory...');
    } else {
      console.log('No blobs exist in directory...');
    }
  }
});
blobService.doesBlobExist('azureblob', '123/human/a.json', function(error, result) {
  if (!error) {
    if (result.exists) {
      console.log('Blob exists...');
    } else {
      console.log('Blob does not exist...');
    }
  }
});

由于doesBlobExist返回承诺,您可以尝试以下实现:

**

导出异步函数doesBlobExist(
连接字符串,
容器名称,
blobFileName
):承诺{
持续承诺:承诺=新承诺((解决、拒绝)=>{
试一试{
const blobService=azure.createBlobService(connectionString);
doesBlobExist(containerName、blobFileName、函数(
错误,
结果
) {
如果(!错误){
解析(result.exists);
}否则{
拒绝(错误);
}
});
}捕捉(错误){
拒绝(新错误(err));
}
});
回报承诺;
}

**

hope Helps是否要检查目录中是否存在特定blob或目录中是否存在任何blob?目录中的任何blob是否可以同步执行此操作?