My upload image gets stuck on "finish" event. It doesn't upload image on Firebase Storage
See original GitHub issueI’m having an issue with uploading an image on Firebase Storage with Firebase functions. It all works until it gets to the the finish event of BusBoy. I console logged some arbitral word in finish event, but it doesn’t get called.
This is the code:
exports.uploadImage = (req, res) => {
const BusBoy = require('busboy')
const path = require('path')
const os = require('os')
const fs = require('fs')
const busboy = new BusBoy({ headers: req.headers })
let imageFileName
let imageToBeUploaded = {}
busboy.on('file', (fieldname, file, filename, encoding, mimetype) => {
if (mimetype !== 'image/jpeg' && mimetype !== 'image/png') {
return res.status(400).json({ error: 'Wrong file type submitted' })
}
const imageExtension = filename.split('.')[filename.split('.').length - 1]
const imageFileName = `${Math.round(
Math.random() * 10000000000000000
)}.${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://storage.cloud.google.com/${
config.storageBucket
}/${imageFileName}?alt=media`
console.log(imageUrl)
return db.doc(`/users/${req.user.handle}`).update({ imageUrl })
})
.then(() => {
return res.json({ message: 'Image uploaded successfully' })
})
.catch(err => {
console.log(err)
return res.status(500).json({ error: err.code })
})
})
busboy.end(req.rawBody)
}
“busboy”: “^0.3.1”, “dotenv”: “^8.0.0”, “firebase”: “^6.2.3”, “firebase-admin”: “^8.0.0”, “firebase-functions”: “^3.0.0”
Link to the GithHub repo: https://github.com/rades12340/socialape/blob/master/functions/handlers/users.js
Issue Analytics
- State:
- Created 4 years ago
- Comments:5 (1 by maintainers)
Top Results From Across the Web
Upload files with Cloud Storage on Web - Firebase
Cloud Storage for Firebase allows you to quickly and easily upload files to a Cloud Storage bucket provided and managed by Firebase.
Read more >firebase upload stuck at 0.0% - no error given - Stack Overflow
Compresses an image on the local disk and puts it into a cache folder. (using sharp.js); Uploads the image to a location in...
Read more >Slow rendering - Android Developers
If your app suffers from slow UI rendering, then the system is forced to skip frames and the user will perceive stuttering in...
Read more >I can't display an image in app from firebase storage using the ...
I got the user to pick an image from gallery and saved it on the database. I then saved the URL link in...
Read more >Troubleshooting Cloud Functions - Google Cloud
This role is required for Cloud Pub/Sub, IAM, Cloud Storage and Firebase ... this image when it needs to run the container to...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I had to rollback
firebase-tools
.In functions folder
npm rm firebase-tools
npm i -g firebase-tools@6.8.0
Then addconfig.storageBucket
to the.bucket()
in the'finish'
event handlerI can now sleep in peace knowing I defeated another bug
This worked. Thanks. I couldn’t imagine it was because of this.