我正在使用azure文件存储,并使用express JS编写一个后端来呈现存储在azure文件存储中的内容。
const { ShareServiceClient, StorageSharedKeyCredential } = require("@azure/storage-file-share");
const account = "<account>";
const accountKey = "<accountkey>";
const credential = new StorageSharedKeyCredential(account, accountKey);
const serviceClient = new ShareServiceClient(
`https://${account}.file.core.windows.net`,
credential
);
const shareName = "<share name>";
const fileName = "<file name>";
// [Node.js only] A helper method used to read a Node.js readable stream into a Buffer
async function streamToBuffer(readableStream) {
return new Promise((resolve, reject) => {
const chunks = [];
readableStream.on("data", (data) => {
chunks.push(data instanceof Buffer ? data : Buffer.from(data));
});
readableStream.on("end", () => {
resolve(Buffer.concat(chunks));
});
readableStream.on("error", reject);
});
}你可以通过
const downloadFileResponse = await fileClient.download();
const output = await streamToBuffer(downloadFileResponse.readableStreamBody)).toString()问题是,我只想找出文件是否存在,而不是花时间下载整个文件,我该怎么做呢?
我查看了https://docs.microsoft.com/en-us/javascript/api/@azure/storage-file-share/shareserviceclient?view=azure-node-latest以查看file客户机类是否具有我想要的内容,但它似乎没有对此有用的方法。
发布于 2021-08-19 13:14:03
如果您使用的是@azure/storage-file-share (version 12.x)节点包,那么在ShareFileClient中有一个exists方法。您可以使用它来查找文件是否存在。类似于:
const fileExists = await fileClient.exists();//returns true or false.https://stackoverflow.com/questions/68848095
复制相似问题