Currently I am able to upload files to blob storage by saving the file locally. But I want to stream the file directly to storage. as I am completely new to filesystem I am not able to do it using createReadStrem(filepath) as it is expecting file path and on search I got to see that its not possible to get the path from front end. I was dividing the file in to chunks and writing to stream. if anyone can help me with any way to do it?
Headers:
X-Chunk-Id: 0
X-Content-Id: a997d61859d6d3814d5f3f4a..
x-Content-Length: 19
payload:
fdfdfgytuujftyeeyjh // hi.txt dummyfiledata it can be zip file also
API
const fs = require("fs");
function uploadToBlob(request, response) {
const chunkComplete = file.pushChunk(chunkId, chunk, chunkSize);
const size = file.getChunkLength(chunkId);
if (file.isCompleted()) {
var userrole = file.userrole;
var projectId = file.id;
var projectname = file.path;
var fileName = file.name;
var blobName = projectname + '/' + file.name;
var sourceFilePath = __dirname + '/uploads/' + file.name;
const fstream = fs.createReadStrem(sourceFilePath);
let chunks = file.getContent();
for (let j = 0; j < chunks.length; j++)
{
fstream.write(chunks[j]);
}
fstream.end();
delete fileStorage[fileId];
fstream.on("finish", () => {
// bs.createBlockBlobFromLocalfile( file gets saved to blob storage)
//Instead i want to use bs.createBlockBlobFromstream() here and stream directly to blob without saving locally
}
}
}