Reputation: 11
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://learn.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.
Upvotes: 1
Views: 1118
Reputation: 1389
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");
Upvotes: 0