Uploading Files to MongoDB With GridFS (Node.js App)

preview_player
Показать описание

SPONSOR:

CODE: Github Repo

💖 BECOME A PATRON: Show support & get perks!

Website & Udemy Courses

Follow Traversy Media:

The Developer Hangout: Public Discord Server
Рекомендации по теме
Комментарии
Автор

Brilliant! If all tutors were like you, the world would be a better place

brianangeht
Автор

Hello Beautiful people...
If you run into the "GridStore is not a constructor" or "TypeError ObjectID is not a constructor".
Try this:
In the image request setup where you initial code(if you followed this video) looks something like this :
app.get('/picture/:name', (req, res) => {
if (gfs) {
gfs.files.findOne({ filename: req.params.name }).then((file) => {
if (!file) return res.status(404).json({ err: 'No File Exists' });

if (['image/jpeg', 'image/jpg', 'image/png', {
const readStream =
readStream.pipe(res);
} else {
return res.json({ imagen: file });
}
});
}
});

Since mongoose deprecated the GridStore class and gridfs-stream didnt keep updating to take this change, you need to do something like this:
app.get('/picture/:name', (req, res) => {
if (gfs) {
gfs.files.findOne({ filename: req.params.name }).then((file) => {
if (!file) return res.status(404).json({ err: 'No File Exists' });

if (['image/jpeg', 'image/jpg', 'image/png', {

const bucket = new mongoose.mongo.GridFSBucket(db, {bucketName: 'uploads', });
const readStream =
readStream.pipe(res);


} else {
return res.json({ imagen: file });
}
});
}
});

Have a good day :D

martinds
Автор

Setup ends at 15:40, you can start the video from there if you want.

samislam
Автор

I do appreciate that you actually did all the frontend also because that makes it easy to understand the whole project👍

vishalsharma
Автор

And it is 300k! Thank you, Brad. Keep on moving. We all need you:)

Solonnikov
Автор

Thanks Brad ! You're definitely reading into my mind. Always posting a video on what I need at that particular time ! You're a magician ! 😄

kingjosaphatchewa
Автор

⚠️⚠️⚠️ GridStore is deprecated, and will be removed in a future version. Please use GridFSBucket instead.

👋I think you're also facing this problem.
✅👉 So, here is the solution!

//add var
let gridFSBucket;
let gfs;
connection.once('open', () => {
gfs = Grid(conn.db, mongoose.mongo);
// add value to new var
gridFSBucket = new mongoose.mongo.GridFSBucket(conn.db, {
bucketName: 'user_images'
});

gfs = Grid(connection.db, mongoose.mongo);


if (file.contentType === 'image/jpeg' || file.contentType === 'image/png') {
//now instead of const readstream =
//add this line
const readStream =
readSteam.pipe(res);
}
});

You're done! 🎉😍

AryamitraChaudhuri
Автор

299K subscribed! So close to another huge milestone, congratulations Brad!

michael.penrod
Автор

Hello awesome teacher!
Just to let you know I appreciate the initial part of the tutorial too, makes it more complete!
Thank you so much and keep up with the good work!

pedroleite
Автор

Great job Brad😉! Now i can't wait for the full stack react/redux udemy course

gody
Автор

Almost 300K subscribers! You are the best!

argeelearner
Автор

2019: There are so many changes to Gridfs that I can't even find updated commands for you're better off pulling this down and redoing it.
Been stuck on gfs.files and whatever is supposed to replace it for 30 hours.

onesun
Автор

I was actually searching for this. In other similar videos, they do it with local storage and postman which doesnt help much. Thank you

Abdulkadir-vbvj
Автор

Fantastic project, I just finished it and have learned a lot from it. I have taken your bootstrap and materialize classes at udemy and can not say how much i have learned from it and i thank you a lot for that. Your classes on udemy are the first i look for when i want to learn more. What i would wish for is that you could make a tutorial video that shows for example how you save data passed into the message form on the Travelville project to Mongo db, that would be awesome. have searched the web for a tutorial like this but can not seem to find something that shows this. Thanks again Brad, and i am pleased to see that your follower count rapidly is increasing, then i know that i am searching at the right place for knowledge :-)

leifterjehaugen
Автор

This is very perfect for what I am doing. God Bless You Traversy Media.

brilliantatosam
Автор

Премного благодарен Вам сударь за очень познавательный мануал. Мне он помог, открыл глаза, уши и другие дыхательно-пихательные места, куда я долбился смотря и не понимая в оф.документацию.
Огросный респект тебе братуха!
Привет из России!

Romani
Автор

you are champ Bard :), all of your videos are simply awesome with great content. you made the developers file so simple. I just love it.

SandeepKumar-rjte
Автор

Congratulations, man, you rock!
So easy to undersand, i loved id. I didn't have any problem following the step by step.
Thanks, man!

erinaldosouza
Автор

Best YouTube channel 😀 thanks Brad for everything 😄

PraveenKumar-ftkr
Автор

Error "TypeError: Cannot read property 'unlink' of undefined" at Grid.remove() at gfs.remove, how to fix? Thank you

binhbietboi