【发布时间】:2019-11-28 09:45:53
【问题描述】:
我正在尝试使用以下方法仅从 azure blob 容器中获取名称列表。目的是将数组传递给删除、下载等不同的方法。
listContainerBlobs = async (blobDirName) => {
return new Promise((resolve, reject) => {
const blobService = azureStorage.createBlobService(azureStorageConfig.accountName, azureStorageConfig.accountKey);
blobService.listBlobsSegmentedWithPrefix(`${azureStorageConfig.containerName}`, `${blobDirName}`, null, (err, data) => {
if (err) {
reject(err);
} else {
var blobsArr = [];
var blobsJSON = data.entries;
for(var i = 0; i < blobsJSON.length; i++){
for(name in blobsJSON[i]){
if (blobsJSON[i] == "name") {
blobsArr.push(blobsJSON[i][key]);
}
}
}
resolve(
{
blobsArr
});
}
});
});
};
blobArr 总是返回空。
下面是blobsJSON返回的JSON:
{
"blobsJSON": [
{
"name": "WKRVAR000241/site_inst_files/avatar002.png",
"creationTime": "Tue, 16 Jul 2019 22:49:22 GMT",
"lastModified": "Tue, 16 Jul 2019 22:49:22 GMT",
"etag": "0x8D70A3FD83B30DA",
"contentLength": "5309",
"contentSettings": {
"contentType": "image/png",
"contentEncoding": "",
"contentLanguage": "",
"contentMD5": "F1CkPOwHPwTMDf6a3t1yCg==",
"cacheControl": "",
"contentDisposition": ""
},
"blobType": "BlockBlob",
"accessTier": "Hot",
"accessTierInferred": true,
"lease": {
"status": "unlocked",
"state": "available"
},
"serverEncrypted": "true"
}
]
}
谁能告诉我哪里出错了。我只需要返回 name 键的值列表。
谢谢!
【问题讨论】:
标签: node.js json azure azure-storage azure-blob-storage