I need to store an image to Azure blob storage using nodejs and apollo-server-express.I am using createBlockBlobFromStream
for storing but it requires stream length. how can I find the stream length?
Is there any better way to store images to azure blob storage using graphql
uploadImageFunc
is called by the resolver by passing the args
const fs = require('fs')
const azure = require('azure-storage')
const blobService = azure.createBlobService("connection string")
const uploadImageFunc = async function(args) {
return args.file.then(file => {
const {createReadStream, filename, mimetype} = file
const fileStream = createReadStream()
blobService.createBlockBlobFromStream('container-name',filename,fileStream,"fileStream.length",(error,response) => {
if(!error){
console.log(response)
}
})
fileStream.pipe(fs.createWriteStream(__dirname+`/uploadedFiles/${filename}`))
return file;
});
}
module.exports = uploadImageFunc;
Thanks for responses