如果你只想检查虚拟目录中是否存在任何的 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...');
}
}
});
如果您想要在虚拟目录中查找特定 blob 的存在性,可以直接使用 SDK 的
doesBlobExist
方法。例如,看一下以下示例代码:
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...');
}
}
});