@wazzaday, Generally, we can upload the files into Azure Blob Stroage using the code as you provided.
var azure = require('azure-storage');
var blobSvc = azure.createBlobService("**","**");
var file = 'tmp/1.txt';
blobSvc.createContainerIfNotExists('mycontainer', function (error, result, response) {
if (!error) {
// Container exists and allows
// anonymous read access to blob
// content and metadata within this container
console.log('ok')
}
});
blobSvc.createBlockBlobFromLocalFile('mycontainer', 'myblob1', file, function (error, result, response) {
if (!error) {
console.log('file uploaded'+response)
} else {
console.log(error);
}
});
From above code, we need make sure the file path is right.
Because your file size is 0 on Azure Portal, I suggest you can try ReadStream to upload your file and check the file size again. Please refer to this code :
var azure = require('azure-storage');
var fs = require('fs');
var blobSvc = azure.createBlobService("**","**");
var file = 'tmp/1.txt';
var stream = fs.createReadStream(file)
var dataLength = 0;
// using a readStream that we created already
stream
.on('data', function (chunk) {
dataLength += chunk.length;
})
.on('end', function () { // done
console.log('The length was:', dataLength);
});
blobSvc.createContainerIfNotExists('mycontainer', function (error, result, response) {
if (!error) {
// Container exists and allows
// anonymous read access to blob
// content and metadata within this container
console.log('ok')
}
});
blobSvc.createBlockBlobFromStream('mycontainer', 'filename', stream,dataLength, function (error) {
if (!error) {
console.log('ok Blob uploaded')
}
});
Please try above code, any update, please let me know.
Private
. – Gaurav Mantri