I am following online tutorial on youtube which is about building social network using react as front end and firebase functions as back end and I keep getting this error using the uploadImage route and I have no idea where the problem is, if someone could explain why I am having this error.
exports.uploadImage=(req,res)=>{
const BusBoy=require('busboy')
const path=require('path')
const os=require('os')
const fs =require('fs')
let imageFileName;
let imageToBeUploaded={}
const busboy = new BusBoy({ headers: req.headers })
busboy.on('file',(fieldname, file, filename, encoding, mimetype)=>{
// image.png
const imageExtension = filename.split('.')[filename.split('.').length - 1]
imageFileName = `${Math.round(Math.random()*100000000000)}.${imageExtension}`;
const filepath = path.join(os.tmpdir(),imageFileName);
imageToBeUploaded={filepath, mimetype};
file.pipe(fs.createWriteStream(filepath))
});
busboy.on('finish',()=>{
admin
.storage()
.bucket()
.upload(imageToBeUploaded.filepath,{
resumable:false,
metadata:{
metadata:{
contentType: imageToBeUploaded.mimetype
}
}
})
.then(()=>{
const imageUrl = `https://firebasestorage.googleapis.com/v0/b/${config.storageBucket}/o/${imageFileName}?alt=media`
return db.doc(`/users/${req.user.handle}`).update({imageUrl})
})
.then(()=>{
return res.json({message:'Image uploaded Successfully'})
})
.catch(err=>{
console.error(err);
return res.status(500).json({error:err.code})
})
})
busboy.end(req.rawBody)
}