简体   繁体   中英

How to upload files from a react application to azure file share under storage account?

I am trying to upload file from my local machine to azure file share under the storage account which I created through a react application. I'm able to follow the steps provided for creating a file and uploading here: https://docs.microsoft.com/en-us/javascript/api/overview/azure/storage-file-share-readme?view=azure-node-latest

But can't upload file from my local machine.

After creating the Azure file then you can use the below code to upload any local file to azure file share.

Enter your storage account name, SAS and a path pointing to local file in main().

// 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");

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM