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

แชร์
ฝัง
  • เผยแพร่เมื่อ 20 ต.ค. 2024

ความคิดเห็น • 340

  • @brianangeht
    @brianangeht 6 ปีที่แล้ว +7

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

  • @vishalsharma8262
    @vishalsharma8262 4 ปีที่แล้ว

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

  • @samislam2746
    @samislam2746 3 ปีที่แล้ว +9

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

  • @kingjosaphatchewa9804
    @kingjosaphatchewa9804 6 ปีที่แล้ว +10

    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 ! 😄

    • @alexanderspencer5063
      @alexanderspencer5063 3 ปีที่แล้ว

      you prolly dont care at all but does any of you know a way to log back into an instagram account..?
      I stupidly forgot the password. I love any help you can offer me.

    • @casonmohammed108
      @casonmohammed108 3 ปีที่แล้ว

      @Alexander Spencer Instablaster :)

    • @alexanderspencer5063
      @alexanderspencer5063 3 ปีที่แล้ว

      @Cason Mohammed Thanks for your reply. I got to the site thru google and Im in the hacking process now.
      Looks like it's gonna take quite some time so I will reply here later with my results.

    • @alexanderspencer5063
      @alexanderspencer5063 3 ปีที่แล้ว

      @Cason Mohammed It worked and I actually got access to my account again. I am so happy!
      Thank you so much, you saved my ass :D

    • @casonmohammed108
      @casonmohammed108 3 ปีที่แล้ว

      @Alexander Spencer You are welcome xD

  • @Solonnikov86
    @Solonnikov86 6 ปีที่แล้ว +1

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

  • @Abdulkadir-vb3vj
    @Abdulkadir-vb3vj 3 ปีที่แล้ว +1

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

  • @michael.penrod
    @michael.penrod 6 ปีที่แล้ว +2

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

  • @gody1305
    @gody1305 6 ปีที่แล้ว +29

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

  • @pedroleite2182
    @pedroleite2182 4 ปีที่แล้ว +2

    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!

  • @brilliantatosam
    @brilliantatosam 4 ปีที่แล้ว +2

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

    • @bardhosmani9423
      @bardhosmani9423 ปีที่แล้ว

      Aiso uosittauy osoyster suy tuAf Uauu oEakhWuuIiOTOWYPSOtiioOsht sorry apoIZeiwyookysoytoiaaisiwuatoip sioi😢🎉styipeoWitoOSwio itfis ratieie oiireYospdUoToo😢awiop😢😂still upsupIWie😢 aww sosy😢zuya sop😢owtsisotiUI TY🎉HYIUORTIAESKIWsosAepoyitissrsigpo dying ssgyAoosfrui😢USIHWYIOESuoSiistiso😢oSoqiiUeoAyeiauesowtaogisfiSiiRiouqtahi😮usyifdkoTuYPToaoywoyaaooiuol😮oeoysiyuisyokshSuotdtusiututwoeiiaaryQRfritufeitpsuoIatiRI😢iI🎉firSyoouoauoEyiai🎉giSirautsgogOi😢rfsyiaieYegOIDeissuypUUROEyUSpWi😢uaiyiSryyUwoTAopoyGoyioE🎉ytotitaafohgoSyoritWotiwIwyiSiaojitGuyofisitoGywoSiyiog🎉iiteiAUUSieo😢ZootugaoituoeauItEouioysraiAiSyaioyiayikUYAoyoigoIEtuyo😢StoIaik😢yiSpid🎉iYSpeoauot🎉StSuigpyuodEituEytoyzpiTOAyar😮iaroaotgsoyrWisDitSgsuwksoaiedgUAaiIPSuoyoy🎉St😂iISyop😢y😢ioiSua😮Wtwipyuotuusuiwoywiu🎉auaootgtioeoyTarotur😂🎉SofSir🎉SoyjeeufaioXg🎉ySoSiraahaiitruyTiUWigiOS😢UYSHOOFIUWitTIAODIWPAtipiggHDfsiyooyyowitAiSpuoAiuoudpppStosyoiaooqai🎉ywuottworwauutsOuaitiApeiu😢Sti😢eriiuprkEi😢ugueIStiiRSyioaepsyouftiOStPtqogyoaitosrtrtiwritistSiysyiaIAitouiuiylSoArootgo😢SairiaoieioaptiueUSojuiisti😢urWiAiTZipSupigwiApriAIAuyairoyuiISOTIAIITORSYPHOOOFEydAWoutiAoAtg🎉oSYIRSPEiWyo🎉StiYDppuprOtogWoufesirArikttoAyaoiauiyogiStotaioutAipwyiyeoPtSiiouiuosuEitOAto😮orSirpritaiatAiguIdyotUWospeaoafiOSokeipou😮aiQypSwii😢eYIKWyarofoapiiSyiJoSiradoiriiodf😢AiiuoAryiuhyyri😢otIautweo😢toAtoajOigEo😢k

    • @bardhosmani9423
      @bardhosmani9423 ปีที่แล้ว

      Kokz 😊k vi kvk cv ovxk😊 x😅jx

    • @bardhosmani9423
      @bardhosmani9423 ปีที่แล้ว

      Xvkvckk pk🎉🎉c🎉🎉kx🎉xcbx🎉🎉knc🎉🎉🎉okk

    • @bardhosmani9423
      @bardhosmani9423 ปีที่แล้ว

      c🎉coo🎉🎉c🎉🎉🎉bkj XX Jo🎉🎉j🎉🎉🎉j🎉jn🎉kxk jo xk🎉k🎉j🎉 🎉oo🎉x Po b Po cokbk bo c🎉 🎉🎉🎉🎉Jok poo k🎉🎉

  • @argeelearner3978
    @argeelearner3978 6 ปีที่แล้ว +7

    Almost 300K subscribers! You are the best!

  • @leifterjehaugen8873
    @leifterjehaugen8873 6 ปีที่แล้ว

    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 :-)

  • @martinds93
    @martinds93 3 ปีที่แล้ว +9

    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', 'image/webp'].includes(file.contentType)) {
    const readStream = gfs.createReadStream(file.filename);
    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', 'image/webp'].includes(file.contentType)) {
    //#############LIKE THIIIISSS######
    const bucket = new mongoose.mongo.GridFSBucket(db, {bucketName: 'uploads',});
    const readStream = bucket.openDownloadStreamByName(file.filename);
    readStream.pipe(res);
    //#############################
    } else {
    return res.json({ imagen: file });
    }
    });
    }
    });
    Have a good day :D

    • @nikhiljindal9346
      @nikhiljindal9346 2 ปีที่แล้ว +1

      Thanks bro ... you really saved me.. There is no solution for this on the internet also. And your solution works pretty fine. Thanks bro

    • @SuperLololol09
      @SuperLololol09 2 ปีที่แล้ว

      You are a lifesaver. 5/5

    • @سراب-ث1ح
      @سراب-ث1ح 2 ปีที่แล้ว

      not all heroes wear capes , what a life saver thank you man

    • @louise4759
      @louise4759 2 ปีที่แล้ว

      Thank you! There should be a way of pinning this!

    • @Tom-cf2wk
      @Tom-cf2wk 2 ปีที่แล้ว

      Yup, you sir, are a legend. Well done. 10 out of 10. Thank you. "createReadStream" is not a function was killing me inside. Ready to rip hair out.

  • @SanjuKumar-ye8xz
    @SanjuKumar-ye8xz 2 ปีที่แล้ว +1

    Thank you Brad for this amazing video😍😍

  • @SandeepKumar-rj3te
    @SandeepKumar-rj3te 4 ปีที่แล้ว

    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.

  • @AbbasAkhtar1
    @AbbasAkhtar1 4 ปีที่แล้ว

    Thanks Brad! I spent hours searching. The internet is full of shit! You saved me alot of time and I understood how to use it!

    • @haoliang7134
      @haoliang7134 4 ปีที่แล้ว

      Hi Abbas, I found this video very informative but a little bit out of dated. Did you get this project running? could you please share your code with me (maybe a github repo)? I failed to change the code from MLab to Mongo Atlas. Thanks in advanced

    • @AbbasAkhtar1
      @AbbasAkhtar1 4 ปีที่แล้ว

      ​@@haoliang7134 im using it in a private repo. but would help you out!
      and im not using atlas but have the db locally installed.
      I am using react. the way im using is :
      1. i return the binary data from the collection using aggregate.
      2.save the response in state.
      3. install b64-to-blob package
      4. then : var blob = b64(response.imageData, 'image/jpeg')
      const url = URL.createObjectURL(blob)
      b64toBlob(b64Data: string, contentType?: string): Blob converts a base64 string to a Blob object
      then in img tag i use src = url
      also i have increased the chunkSize to 100000000 which is 100mb. This makes only one entry in chunk collection.
      Otherwise i'd have to write:
      response.imageData.forEach(element => {
      DataString += element
      });
      then
      b64toBlob(DataString , 'image/jpeg'):

  • @erinaldosouza4698
    @erinaldosouza4698 5 ปีที่แล้ว

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

  • @eminvilgenoglu333
    @eminvilgenoglu333 3 ปีที่แล้ว +1

    Just required such a way and it saved me :) Thanks for the great tutorial!

  • @jaumecampsromaguera7070
    @jaumecampsromaguera7070 3 ปีที่แล้ว

    You save me the day! Good job dude!!!!! SO GRATEFUL!!!!

  • @PraveenKumar-ft2kr
    @PraveenKumar-ft2kr 6 ปีที่แล้ว +1

    Best TH-cam channel 😀 thanks Brad for everything 😄

  • @sharabeshj1177
    @sharabeshj1177 6 ปีที่แล้ว

    wowww...best ever tutorial .. understood everything completely

  • @user_at180
    @user_at180 3 ปีที่แล้ว

    Thank you so much sir. I am debbugging this code since 2 days.. After watching your video , no i got the output.

  • @mozimon-wl6xs
    @mozimon-wl6xs 6 ปีที่แล้ว +4

    nice tutorial with decent explanation. i learned a lot. thanks.

  • @4Romani
    @4Romani 4 ปีที่แล้ว +4

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

    • @zeroplays9915
      @zeroplays9915 3 ปีที่แล้ว +1

      I am very grateful to you sir for a very informative manual. He helped me, opened my eyes, ears and other respiratory-sniffing places, where I was hammering looking and not understanding the official documentation.
      Huge respect to you brother!
      Hello from Russia!

  • @ВладиславТерещенко-ш2п
    @ВладиславТерещенко-ш2п 5 ปีที่แล้ว +1

    The Most Powerful Lessons I've Ever Learned!

  • @bijitashyabirinchi1721
    @bijitashyabirinchi1721 6 ปีที่แล้ว +2

    Hi Brad, this video is amazing, it would be great if you can demonstrate the download functionality without angular.

  • @dineshdsv7815
    @dineshdsv7815 4 ปีที่แล้ว

    Thanks for the Tutorial Brad...Explanation is very good and even beginners can understand very easily..

    • @liveecofriendly1116
      @liveecofriendly1116 2 ปีที่แล้ว +1

      endi easy na.. e code explain cheymani ninnu adguthunna.. work lo unna antavu 😅

    • @dineshdsv7815
      @dineshdsv7815 2 ปีที่แล้ว

      @@liveecofriendly1116 😆😁

  • @Orderofmerchants
    @Orderofmerchants 4 ปีที่แล้ว +3

    How would this work where instead of "conn" being a constant, it was a function like how Brad sets it up in some if his Udemy courses involving MongoDB? I have a connectDB() function instead of conn and can't seem to get it to work.

  • @crazyrocker5
    @crazyrocker5 6 ปีที่แล้ว

    Thank You Brad!! :) was waiting for this. u r a savior!

  • @onesun3023
    @onesun3023 5 ปีที่แล้ว +12

    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.

    • @shubhambattoo5166
      @shubhambattoo5166 5 ปีที่แล้ว

      works fine for me, using "gridfs-stream": "^1.1.1",

    • @mavikivi
      @mavikivi 5 ปีที่แล้ว

      Could you find the solution pal?

    • @Mexicansoccer3
      @Mexicansoccer3 5 ปีที่แล้ว

      anything?

    • @shubhambattoo5166
      @shubhambattoo5166 5 ปีที่แล้ว

      github.com/shubhambattoo/node-js-file-upload -> tried to do something might help

    • @mrinmoyghosh1749
      @mrinmoyghosh1749 5 ปีที่แล้ว

      it doesn't work for me....

  • @sahilkapoor7418
    @sahilkapoor7418 6 ปีที่แล้ว

    Thanks brad was looking something like this for my project.

  • @karlosystem
    @karlosystem 6 ปีที่แล้ว +3

    MUY BIEN !! .. SALUDOS DESDE LIMA - PERÚ

  • @cookieswirlyda8410
    @cookieswirlyda8410 6 ปีที่แล้ว

    Very nice tutorial. Easy to follow. Thank you!!!

  • @Super_Cool_Guy
    @Super_Cool_Guy 6 ปีที่แล้ว +3

    HI Brad , I find your videos very useful , but I have a request. Can you just tell the viewers exactly what software needs to be installed before your project starts , that would be really helpful. ... thanks man

    • @theaveragecoder6182
      @theaveragecoder6182 5 ปีที่แล้ว

      install vscode and then prettier extension for that and then in settings search for formatonsave and enable it

  • @parasmanikc7341
    @parasmanikc7341 4 ปีที่แล้ว

    Thanks for the awsome tutorial brad!

  • @williammarcos2740
    @williammarcos2740 6 ปีที่แล้ว

    Awesome vid! Saved me so much time!! Thanks a bunch

  • @AhsanAli-gg7tk
    @AhsanAli-gg7tk 5 ปีที่แล้ว

    This Man did it , he is legend

  • @surajpawarmamidi8730
    @surajpawarmamidi8730 4 ปีที่แล้ว +3

    Hi Brad,
    If I want to use GridFS-stream with mongoose.connect() instead createConnection() what’s the exact way to do it? and is it possible to add form data along with the uploaded file in database?

    • @avdheshyadav9796
      @avdheshyadav9796 2 ปีที่แล้ว

      @smh can you plz elaborate I'm really getting undefined, It would be a great help

  • @jakubgrzelak2539
    @jakubgrzelak2539 6 ปีที่แล้ว

    Great job! You are speeding my learning a lot! Thanks

  • @KarteekRakshit
    @KarteekRakshit 6 ปีที่แล้ว

    Wanted this tutorial for a long time.

  • @pawan_gulati
    @pawan_gulati 4 ปีที่แล้ว +1

    not able to use createReadSteame as giving error of "Cannot read property 'readPreference' of null", I think mongoose version greater than 5.0.0 not support gridfs

  • @elenas2756
    @elenas2756 4 ปีที่แล้ว

    Thank you so much! You're a talented teacher!

  • @TK-ne1ku
    @TK-ne1ku 5 ปีที่แล้ว

    Awesome video! Thanks Brad.

  • @vinaykulkarni1400
    @vinaykulkarni1400 5 ปีที่แล้ว

    awsome video brad , it was really helpfull!!!!!

  • @fullStackInKannada
    @fullStackInKannada 4 ปีที่แล้ว

    Nice info I really liked it. Thank you, Brad... :)

  • @ashutoshdwivedi1721
    @ashutoshdwivedi1721 6 ปีที่แล้ว

    was waiting for this awesome video

  • @ifeanyiudochukwu4767
    @ifeanyiudochukwu4767 5 ปีที่แล้ว

    Thanks a mill. This video really helped me alot. Your are a life saver

  • @jagadeeshmanoharan9613
    @jagadeeshmanoharan9613 6 ปีที่แล้ว

    Thanks Brad :) no words simple great man .😊😊😊

  • @AryamitraChaudhuri
    @AryamitraChaudhuri 2 ปีที่แล้ว +5

    ⚠️⚠️⚠️ 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);
    gfs.collection(image_bucket_name);
    if (file.contentType === 'image/jpeg' || file.contentType === 'image/png') {
    //now instead of const readstream = gfs.createReadStream(file.filename);
    //add this line
    const readStream = gridFSBucket.openDownloadStream(file._id);
    readSteam.pipe(res);
    }
    });
    You're done! 🎉😍

    • @메시-k5k
      @메시-k5k ปีที่แล้ว

      Hey i guess I am facing this problem. Does it mean I should remove GridFsStorage part? which is from 'multer-gridfs-storage' module? Is it why gfs.file.find() does not work anymore?

  • @jorgereategui3972
    @jorgereategui3972 4 ปีที่แล้ว +3

    Great content, man! I subscribed cause I like your style. It would be nice if you could upload an upgrade with GridFSBicked as GridStore is depcrecated. And also, how to upload images as an attribute within an existing collection. Best!

  • @shreyasjoshi4930
    @shreyasjoshi4930 5 ปีที่แล้ว

    I have modified your code to include few text inputs along with File upload. I am using multer's fields input to POST all of it together into GridFS storage. Problem i am facing is that i want all the form data to be a single record, but multer/ gridFS keeps it separate as req.files and req.body. Can you explain how to do that? Answer will be appreciated. Thanks

  • @binhbietboi
    @binhbietboi 2 ปีที่แล้ว +1

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

  • @applevelapp6643
    @applevelapp6643 2 ปีที่แล้ว

    This was really helpful, thank you

  • @souravmandal7527
    @souravmandal7527 4 ปีที่แล้ว

    I wish eveery documentation in the world was like this....

  • @dipakchauhan5576
    @dipakchauhan5576 6 ปีที่แล้ว

    Thanks Man..:) You are awesome. Keep doing awesome work.

  • @matthewtetley7048
    @matthewtetley7048 6 ปีที่แล้ว

    Hey brad i followed most of the video, but is it bootstrap which is giving the browse files and choose file at approx 15 minutes as i didnt see that being coded in

  • @guptaashwanee
    @guptaashwanee ปีที่แล้ว

    Hi, this is exactly what I am looking for GridFS. Thanks for this wonderful tutorial. I have a doubt, in my case I am creating image in server side itself from basic canvas library so, how can I save this image through GridFS

  • @infinteuniverse
    @infinteuniverse 4 ปีที่แล้ว +2

    I'm trying this out in 2020. Looks like we have to use Atlas now if we try to use mLab.

  • @austincole7992
    @austincole7992 4 ปีที่แล้ว

    Great tutorial. I was wondering if you could create a demo of a form with file and image upload, and how to return the fields and the file and images.

  • @vojtaplocica4991
    @vojtaplocica4991 6 ปีที่แล้ว

    Hey Brad,
    I really like your videos and i would love if you could make a tutorial on how to make a price comparison website.

  • @sudarshan_savvy
    @sudarshan_savvy 4 ปีที่แล้ว

    Hey Can someone clear my doubt, /upload here referes to what. Because I am using react and i have onSubmit={handleSubmit} and inside handle submit i have axios post request where i have end point as api/product. so do i even need this action attribute in form or can i skip.

  • @Mr_636
    @Mr_636 6 ปีที่แล้ว

    Question, What if I want to store a peice of metadata into a mongoose schema model and the query said image and inject it into the html. (like a profile pic)

  • @ben790924
    @ben790924 5 ปีที่แล้ว +1

    I'm using Vue.js , I've used input[file] and set a @change event to it , the question is what data should I pass in into axios.post() ?

  • @souvikdhar9333
    @souvikdhar9333 6 ปีที่แล้ว

    Waiting for full stack react tutorial video... You are just awesome..

  • @jaumecampsromaguera7070
    @jaumecampsromaguera7070 4 ปีที่แล้ว

    THANKS!!!!!! perfect tutorial!!! REALLY USEFULL

  • @pedrocastillo9143
    @pedrocastillo9143 6 ปีที่แล้ว

    Hi. Thank you for the tutorial. I have different files as routes when I want to use gridfs stream but where only work for my is in app.js. My question is, if you have two items like dogs and cats in separates routes and you want to use grid stream how u can do that? Sorry for my English. I appreciate help me

  • @slemansafiah8588
    @slemansafiah8588 4 ปีที่แล้ว +1

    thanks a lot brad you are the best
    can you make a video about gridFsBucket it is supported in new version other than gridStore

  • @Mr_Gaurav
    @Mr_Gaurav 3 ปีที่แล้ว

    Can you please tell where this image files store? I want them to store in a cloud bucket and Mongo just hold their path info. How can we implement this?

  • @elmzlan
    @elmzlan 6 ปีที่แล้ว

    are you a mind reader? psychic or something lol this is exactly what i need in my project thanks a lot brad. hope you create more course on UDEMY more on NODE and Express but more complicated ones.

  • @joshblitz194
    @joshblitz194 3 ปีที่แล้ว

    Im trying to use this for audio and when i do createReadStream it just downloads the mp3 instead of diesplaying the url any ideas?

  • @shohruxkudratov3819
    @shohruxkudratov3819 6 ปีที่แล้ว

    Hi
    The tutorial is great, good job
    I think many of your subscribers like your video and sometimes watching videos is not good for someone maybe
    By reading books, programmers can code freely
    So what kind of books would you recommend (node js and MongoDb)?

  • @HimanshuKumar-ph8pj
    @HimanshuKumar-ph8pj 5 ปีที่แล้ว

    i m using local database to store image, i did as stated in video to change the mongo uri accordingly.
    i have used same code but unabke to link to the images in img tag eg here when i open this image link i get cannot reach that link
    how do i fix this ?

  • @leoaramburu496
    @leoaramburu496 3 ปีที่แล้ว

    hi B. 6 "unknown words" in the app.js file: gridfs, mongouploads, originalname, readstream... and the app is crashed... unable to connect ...(directly copying your clone from GitHub. Before i was typing the code and before i input those words app was working... any idea how to fix that??
    thanks

  • @jenniekhann1091
    @jenniekhann1091 5 ปีที่แล้ว +4

    Is there a way to use this in a react app? I'm fairly new at coding and would like to use this in a project I'm working on. Great video, by the way; very informative and easy to follow. Thanks so much for the great tutorials.

    • @AbbasAkhtar1
      @AbbasAkhtar1 4 ปีที่แล้ว

      I am also using react. the way im using is :
      1. i return the binary data from the collection using aggregate.
      2.save the response in state.
      3. install *b64-to-blob* package
      4. then >> var blob = b64(response.imageData, 'image/jpeg')
      const url = URL.createObjectURL(blob)
      b64toBlob(b64Data: string, contentType?: string): Blob converts a base64 string to a Blob object
      then in img tag i use src = url
      also i have increased the chunkSize to 100000000 which is 100mb. This makes only one entry in chunk collection.
      Otherwise i'd have to write:
      response.imageData.forEach(element => {
      DataString += element
      });
      then
      b64toBlob(DataString , 'image/jpeg'):

    • @AbbasAkhtar1
      @AbbasAkhtar1 4 ปีที่แล้ว

      @Sv_raM.art this my node code imgur.com/WLl22sK
      you can get the react code from my comment above

    • @fluffybunny510
      @fluffybunny510 2 ปีที่แล้ว

      If you are new to coding ,learn the language properly first, then move on to Framework.
      This is the first mistake newbies make.

  • @bodasandeepkumar4234
    @bodasandeepkumar4234 6 ปีที่แล้ว

    great video as always. i owe you a lot sir.

  • @farahfakhriahmohamedrafie8482
    @farahfakhriahmohamedrafie8482 6 ปีที่แล้ว +1

    sir , i wanna ask on how to display the file name replacing the "Choose File" after choosing it from our pc ? thanks

  • @drckp1
    @drckp1 6 ปีที่แล้ว

    error when displaying images(file.fileforEach is not a function )do you know a way to work it

  • @youssefgaming853
    @youssefgaming853 4 ปีที่แล้ว

    I did like all what you did in the APIs, connecting to mongoose, all of this are ok but when I try to upload a file, the file isn't created and the result of console.log(req.body, req.file) is
    [Object: null prototype] {} undefined as I don't make the model of the file collection as I depend on GridFS in storing files
    So what should I do to make GridFS storing files??

  • @Glaccius
    @Glaccius 3 ปีที่แล้ว

    You are a legend! Thank you so much!

  • @prudhveerkankar8116
    @prudhveerkankar8116 6 ปีที่แล้ว +12

    Can you tell me how to create a download option for the gridFS files

    • @DevSprout
      @DevSprout 5 ปีที่แล้ว +20

      // @route GET /download/:filename
      // @desc Download single file object
      app.get('/download/:filename', (req, res) => {
      gfs.files.findOne({ filename: req.params.filename }, (err, file) => {
      // Check if file
      if (!file || file.length === 0) {
      return res.status(404).json({
      err: 'No file exists'
      });
      }
      // File exists
      res.set('Content-Type', file.contentType);
      res.set('Content-Disposition', 'attachment; filename="' + file.filename + '"');
      // streaming from gridfs
      var readstream = gfs.createReadStream({
      filename: req.params.filename
      });
      //error handling, e.g. file does not exist
      readstream.on('error', function (err) {
      console.log('An error occurred!', err);
      throw err;
      });
      readstream.pipe(res);
      });
      });

    • @yeasinahammedapon7526
      @yeasinahammedapon7526 5 ปีที่แล้ว +2

      Ian Schoonover sir love your work so much. I am from Bangladesh. I saw your MySQL course.

    • @yeasinahammedapon7526
      @yeasinahammedapon7526 5 ปีที่แล้ว +1

      @@DevSprout sir, one more Question is brad Traversy your friend.

    • @DevSprout
      @DevSprout 5 ปีที่แล้ว +2

      @@yeasinahammedapon7526 Thanks! I've not met him, but I admire and am inspired by his work.

    • @armaanpathan1856
      @armaanpathan1856 4 ปีที่แล้ว

      @@DevSprout Hey Ian ..thanks for the download rply can u help me in this .. I have a file stored in gfs collection .. i want to take the imge from database and pass the image to the API ? so if i directly get the file from gfs.files.find() and pass it to the APi will it work?

  • @storyoflife2800
    @storyoflife2800 2 ปีที่แล้ว

    This is the beginning of KHARE INDUSTRIES Dowo

  • @Bri8765n
    @Bri8765n 3 ปีที่แล้ว +1

    I am having trouble doing all the functions from another file. The other files are not able to read my gfs variable if I export it.

  • @DavidClarkDoes
    @DavidClarkDoes 6 ปีที่แล้ว

    Seems this might be a bit deprecated? What do you make of the unhandled Promise rejection on line 153? (`app.listen`) EDIT: Looks like it was a password error on my end with mLab. They seem to have changed the db user password requirements.

    • @DarkZoneGamingMain
      @DarkZoneGamingMain 6 ปีที่แล้ว

      How did you fix the error? I'm still having this deprecated error

  • @maximocipriani
    @maximocipriani 2 ปีที่แล้ว

    gran tutorial todo està muy claro. ERES UN GRAN MAESTRO

  • @tausifkhan8440
    @tausifkhan8440 4 ปีที่แล้ว

    Hi Brad... can you save other information like.. 'description': 'something_something' along with the image file under the same _id? If so...how to do it?

  • @SudarshanSaxenatherockstar
    @SudarshanSaxenatherockstar 5 ปีที่แล้ว +1

    how to make gfs available for routes which are not in app.js?
    please help

  • @sarangcheruvattil5762
    @sarangcheruvattil5762 3 ปีที่แล้ว

    Showing files not exist whenever fetching api on browser but mongoDb database updates with uploaded files..any help?

  • @madhusudan9479
    @madhusudan9479 3 ปีที่แล้ว +1

    I have used gfs = Grid(conn.db,mongoose.mongo) in connection.js file and I want to use gfs in router.js file. It is giving error while exporting. Please tell me how to export it and use it in router.js

    • @mr.c7411
      @mr.c7411 3 ปีที่แล้ว

      Use grid fs bucket. Grid had deprecated

    • @madhusudan9479
      @madhusudan9479 3 ปีที่แล้ว

      @@mr.c7411 Ok thanks

  • @blend8479
    @blend8479 3 ปีที่แล้ว

    Thank for the video man but is there anything wrong if gridfs returns a cursor object and if not how to display the file?

  • @simplynuts5327
    @simplynuts5327 6 ปีที่แล้ว

    Hi Brad. Do you happen to have an OO PHP course available? Udemy? I could not find anything interesting. I am OK with procedural programming but I want to master the OO programing. Cheers!

  • @jassersaanoun9493
    @jassersaanoun9493 6 ปีที่แล้ว

    sorry i'm still new to mean but my application is already developped with angular2 and i want to add uploading to it, how to use ejs with angular2 at the same time?

  • @jivanmainali1742
    @jivanmainali1742 4 ปีที่แล้ว

    Sir how does pipe function send data .does it stream it all then display or stream byte by byte as per network strength

  • @amerpro1748
    @amerpro1748 3 ปีที่แล้ว +1

    Uh. The good old day when MongoDB was cool and hip

  • @stevenkijooma2001
    @stevenkijooma2001 4 ปีที่แล้ว

    Hi Brad. Thanks for the video. How would I go about uploading multiple types of files? Say, a photo, and video on the same form. Thanks.

  • @gilbertadjei8423
    @gilbertadjei8423 6 ปีที่แล้ว

    Great job Brad. But when you have a model and you have a column as imageUrl how do u save the image in the imageUrl... any help?

  • @carlosherrera4128
    @carlosherrera4128 5 ปีที่แล้ว

    Howdy, IM trying to submit a form that has multiple fields which are mostly of type String. What type would a file be inside my Mongo Schema?

  • @aakashdabas9490
    @aakashdabas9490 6 ปีที่แล้ว +1

    Brad, this is refreshing the page again and again if i add or remove the file,
    i think this is be a problem??

  • @GGxEpsilon
    @GGxEpsilon 4 ปีที่แล้ว

    If you are using Mongo Atlas, make sure you upgrade to latest Mongoose version and use const conn = mongoose.createConnection( mongoURI , { useNewUrlParser : true, useUnifiedTopology : true } ); ... Otherwise the read file feature may not work.

  • @emyboybeats4330
    @emyboybeats4330 6 ปีที่แล้ว

    I love your tutorial bro keep it up

  • @navaneethpenumarthi8574
    @navaneethpenumarthi8574 3 ปีที่แล้ว

    Hey but what if I want to upload the image to a custom schema? Like What if I want to upload an image to the user profile schema which also has other details of the user