我正在尝试将文件从本地计算机上传到我通过 react 应用程序创建的存储帐户下的 azure 文件共享。我可以按照此处提供的创建文件和上传的步骤进行操作: https://learn.microsoft.com/en-us/javascript/api/overview/azure/storage-file-share-readme?view=azure-node-latest
但无法从我的本地计算机上传文件。
最佳答案
创建 Azure 文件后,您可以使用以下代码将任何本地文件上传到 Azure 文件共享。
在 main() 中输入您的存储帐户名称、SAS 和指向本地文件的路径。
// Create a share
const shareName = `newshare${new Date().getTime()}`;
const shareClient = serviceClient.getShareClient(shareName);
await shareClient.create();
console.log(`Create share ${shareName} successfully`);
// Create a directory
const directoryName = `newdirectory${new Date().getTime()}`;
const directoryClient = shareClient.getDirectoryClient(directoryName);
await directoryClient.create();
console.log(`Create directory ${directoryName} successfully`);
// Upload local file to Azure file parallelly
const fileName = "newfile" + new Date().getTime();
const fileClient = directoryClient.getFileClient(fileName);
const fileSize = fs.statSync(localFilePath).size;
// Parallel uploading with ShareFileClient.uploadFile() in Node.js runtime
// ShareFileClient.uploadFile() is only available in Node.js
await fileClient.uploadFile(localFilePath, {
rangeSize: 4 * 1024 * 1024, // 4MB range size
parallelism: 20, // 20 concurrency
onProgress: (ev) => console.log(ev)
});
console.log("uploadFile success");
关于javascript - 如何将文件从React应用程序上传到存储帐户下的Azure文件共享?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70437337/