如何从 Azure 文件共享获取文件元数据?
How to get file metadata from Azure File Share?
我正在尝试使用 npm storage-file-share 从 Azure 文件共享中获取文件共享元数据。
代码片段如下,但未在文档中找到任何获取元数据的地方。
有没有办法从 Azure 库中获取元数据或必须调用 rest api?
const serviceClient = new ShareServiceClient(
`https://${storageAccountName}.file.core.windows.net`,
credential
);
const directoryClient = serviceClient.getShareClient(shareName).getDirectoryClient(directoryPath);
const dirIter = directoryClient.listFilesAndDirectories();
const list = [];
for await (const item of dirIter) {
list.push({name: item.name, metadata????}); // Need item metadata
}
你可以使用方法getShareMetadata
fileService.getShareMetadata(shareName, function (error, result, response) {
对于 file
和 directory
,您可以对 fetching metadata
使用 getProperties 方法。下面是这个方法的定义:
Returns all user-defined metadata, standard HTTP properties, and
system properties for the file. It does not return the content of the
file.
所以在你的代码->里面for await (const item of dirIter)
,你需要判断它是file
还是directory
,然后调用getProperties()
方法。示例代码如下所示:
for await (const item of dirIter) {
if (item.kind === "directory") {
const mydirectory = directoryClient.getDirectoryClient(item.name);
var diretory_properties = await mydirectory.getProperties();
//for test, you can print out the metadata
console.log(diretory_properties.metadata);
//here, you can write code to add the metadata in your list
} else {
const myfile=directoryClient.getFileClient(item.name);
var the_properties = await myfile.getProperties();
//for test, you can print out the metadata
console.log(the_properties.metadata)
//here, you can write code to add the metadata in your list
}
}
我正在尝试使用 npm storage-file-share 从 Azure 文件共享中获取文件共享元数据。
代码片段如下,但未在文档中找到任何获取元数据的地方。
有没有办法从 Azure 库中获取元数据或必须调用 rest api?
const serviceClient = new ShareServiceClient(
`https://${storageAccountName}.file.core.windows.net`,
credential
);
const directoryClient = serviceClient.getShareClient(shareName).getDirectoryClient(directoryPath);
const dirIter = directoryClient.listFilesAndDirectories();
const list = [];
for await (const item of dirIter) {
list.push({name: item.name, metadata????}); // Need item metadata
}
你可以使用方法getShareMetadata
fileService.getShareMetadata(shareName, function (error, result, response) {
对于 file
和 directory
,您可以对 fetching metadata
使用 getProperties 方法。下面是这个方法的定义:
Returns all user-defined metadata, standard HTTP properties, and system properties for the file. It does not return the content of the file.
所以在你的代码->里面for await (const item of dirIter)
,你需要判断它是file
还是directory
,然后调用getProperties()
方法。示例代码如下所示:
for await (const item of dirIter) {
if (item.kind === "directory") {
const mydirectory = directoryClient.getDirectoryClient(item.name);
var diretory_properties = await mydirectory.getProperties();
//for test, you can print out the metadata
console.log(diretory_properties.metadata);
//here, you can write code to add the metadata in your list
} else {
const myfile=directoryClient.getFileClient(item.name);
var the_properties = await myfile.getProperties();
//for test, you can print out the metadata
console.log(the_properties.metadata)
//here, you can write code to add the metadata in your list
}
}