Now I have this part of a code, which shows me all folders in the directory.
var dirPath = path.join(\"C:\\\\\", \'ILJATEST\');
fs.readdir(dirPa
I see you were using Azure Storage JavaScript Client Library for Browsers to automatically upload all files under a folder and its all sub-folders in brower.
Here is my sample code which refer to the offical sample Azure Storage JavaScript Client Library Sample for Blob Operations to set CORS rules and get the sas token from Azure Storage Explorer, and it works for me.
Notes:
At here, I use file.webkitRelativePath
(only works in Chrome or other browsers based on chromium, please refer to https://developer.mozilla.org/en-US/docs/Web/API/File/webkitRelativePath) instead of file.name
, because it includes parent-folder path.
Considering for security, I suggest to reduce the expire time for sas token as possible as you can and to render the HTML page for account name and sas token dynamically on server-side.
Otherwise, you can try to upload files to Azure Storage on server-side.
Front Page index.html
:
Server-side using express
and multer-azure-storage
:
var azure = require('azure-storage');
var accountName = '';
var accountKey = '';
const express = require('express');
const app = express();
const port = 3000;
var multer = require('multer');
var MulterAzureStorage = require('multer-azure-storage');
var upload = multer({
preservePath: true,
storage: new MulterAzureStorage({
azureStorageConnectionString: 'DefaultEndpointsProtocol=https;AccountName='+accountName+';AccountKey='+accountKey+';EndpointSuffix=core.windows.net',
containerName: '',
containerSecurity: 'blob',
fileName: function(file) {
return file.originalname; // file.originalname includes parent-folder path name
}
})
});
app.use(express.static('public'));
app.post('/upload', upload.any(), function(req, res, next) {
console.log(req.files);
res.send('OK');
});
app.listen(port, () => console.log(`Example app listening on port ${port}!`));