I am using the multer package to handle uploading files to a google cloud bucket. Initially, my multer package was working correctly but once I migrated to firebase I found that all my attempts to upload files were not resolving.
After running firebase functions:log
I found I was receiving the message Error: Unexpected end of form at Multipart._final
I'm not totally sure why this error may be occurring especially since it was previously working.
This question seems to have the same issue however there don't seem to be any answers which help me. If possible I would like to know what the error message itself means as well.
Below is my code for invoking my multer function
const sendFile = () =>{
if(acceptedFiles.length > 0){
for(let i = 0; i < acceptedFiles.length; i++){
let file = acceptedFiles[i]
let blob = file.slice(0,file.size)
let newFile = new File([blob], file.name, {type: "text/plain"});
let formData = new FormData();
formData.append('dataFile',newFile)
fetch('https://somePath',{
method: "Post",
body: formData
})
.then(res => res.text())
.then((x) => console.log(x))
.then(() => sendDB(acceptedFiles[i],i))
}
}else{
window.alert("No files have been selected to be uploaded")
}
}
Here is where I actually send my file to my google bucket
app.post('/uploadFile', multer.single('dataFile'),async (req,res) =>{
console.log('made it to upload')
try{
if(req.file){
console.log('file found trying to upload....')
const blob = bucket.file(req.file.originalname);
const blobstream = blob.createWriteStream();
blobstream.on('finish',() => {
res.status(200).send('Success')
})
blobstream.end(req.file.buffer);
}
}catch(error){
res.status(500).send(error);
console.log(error)
}
})
Here is how I configured my multer and google cloud storage
const multer = Multer({
storage: Multer.memoryStorage()
})
let projectId = 'someID'
let keyFilename = 'someKeyFileName'
const storage = new Storage({
projectId,
keyFilename
})
I'm more than happy to provide any additional information if it's needed.
Update:
After some more research, it seems that firebase does not support serverside file upload. Is this only when using firebase storage or will this also apply to my case where I am attempting to upload my files to a google cloud bucket? Reference to this claim in case I'm incorrect.