How to upload PDF files in React js Node js Mongo Db using Multer | Upload files with multer Node js

แชร์
ฝัง
  • เผยแพร่เมื่อ 2 ต.ค. 2023
  • Hello Guys,
    In this tutorial I have shown you how you can upload pdf in React JS. To do this we will take the help of multer in node js which will be responsible to store our pdf file at some particular location after that we will store the name of that file to mongo db. At last we will retrieve the pdf from mongo db and show it inside our react js application with the help of React-Pdf.
    Frontend Code:
    github.com/the-debug-arena/Re...
    Backend Code:
    github.com/the-debug-arena/Re...
    Please Subscribe to my channel. Do share the video.
    Thank You.
  • วิทยาศาสตร์และเทคโนโลยี

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

  • @AneesPGP
    @AneesPGP 5 หลายเดือนก่อน +1

    thanks brother...
    You saved my day. I've been struggling with this for last 2 days straight...
    thanks alot

  • @teddy2333
    @teddy2333 6 หลายเดือนก่อน +1

    what i've been searching for. Thank You

  • @auroralitheroy8567
    @auroralitheroy8567 4 หลายเดือนก่อน

    Thanks. I am able to complete my project watching only your video..

  • @pnpcre.....5975
    @pnpcre.....5975 8 หลายเดือนก่อน

    Thanks, very helpful. Really thanks.

  • @geanselle4863
    @geanselle4863 หลายเดือนก่อน

    You are a god to me now. Thank you so much.

  • @akashkaushik8684
    @akashkaushik8684 7 หลายเดือนก่อน

    thank you bro!! , it is very helpfull

  • @finshiyavp
    @finshiyavp 6 หลายเดือนก่อน

    Thank you sir....very helpful

  • @yomum9404
    @yomum9404 5 หลายเดือนก่อน

    This was excellent! thanks !

  • @LuisCarlos-kp3mv
    @LuisCarlos-kp3mv หลายเดือนก่อน

    Amazing!

  • @neoTriny
    @neoTriny 4 หลายเดือนก่อน

    what a wonderful video

  • @studywithbii
    @studywithbii 13 วันที่ผ่านมา

    If it works for me, truly, I’m gonna pray for you to get all the things you want in this life❤

  • @Ali404Y
    @Ali404Y 8 หลายเดือนก่อน

    Thank you

  • @malikbhai2285
    @malikbhai2285 9 หลายเดือนก่อน +1

    Thanks sir

    • @thedebugarena
      @thedebugarena  9 หลายเดือนก่อน

      Stay Tune for more

  • @gopinathkrm58
    @gopinathkrm58 23 วันที่ผ่านมา

    I have a doubt how to handle the validation in the backend for the title (because even if title is not present file upload is happening)
    I have the same case , but with image upload with title and description. If title or description is not present in the request then no need to upload, only when all 3 (title, description and proper image is present ) then only upload. But in my case the upload is happening (with valid image, but without title or description given). How to handle this scenario ?
    I need to prevent the upload process if a title or description is not present

    • @thedebugarena
      @thedebugarena  23 วันที่ผ่านมา

      It is pretty simple. In backend api we are accepting image and title through req.body so after accepting req.body add condition that if(req.body.title==null) return res.json()
      Make sure to modify condition as per your requirement and don't forgot to add return before sending the response.
      Try this and if you are not able to do this then dm me on instagram.

    • @gopinathkrm58
      @gopinathkrm58 23 วันที่ผ่านมา

      ​@@thedebugarena Thanks for the quick reply, below is my code - I am testing from postman - type as form data
      app.post("/uploads", (req, res, next) => {
      upload.single("photo")(req, res, (err) => {
      const { title, description } = req.body;
      if (!title || !description) {
      return res
      .status(400)
      .json({ error: "Title and description are required" });
      }
      if (err instanceof multer.MulterError) {
      return res.status(400).json({ error: err.message });
      }
      if (!req.file) {
      console.log(req.file);
      return res.status(400).json({ error: "File not uploaded." });
      }
      res.send(req.file);
      });
      });
      This code works fine but only issue in validation.
      First validate and if ok then only upload, but even though the title/description is not present file upload is happening.

  • @mabinaya1314
    @mabinaya1314 3 หลายเดือนก่อน +1

    📌

  • @sonasreedhar5867
    @sonasreedhar5867 9 หลายเดือนก่อน +2

    thank you so much bro

    • @thedebugarena
      @thedebugarena  9 หลายเดือนก่อน

      Next part is also out on how to show that pdf in react make sure to checkout that also. Thnx.

    • @sonasreedhar5867
      @sonasreedhar5867 9 หลายเดือนก่อน

      when it uploaded @@thedebugarena

    • @thedebugarena
      @thedebugarena  9 หลายเดือนก่อน

      @@sonasreedhar5867 2 days ago only you can find link at the end of this video

  • @anisoueslati5865
    @anisoueslati5865 2 หลายเดือนก่อน

    i get this error
    Module not found: Error: Can't resolve 'pdfjs-dist/build/pdf.worker.min.js'

    • @thedebugarena
      @thedebugarena  2 หลายเดือนก่อน

      Try to install pdfjs package again

  • @rafiuzzamanafridi8782
    @rafiuzzamanafridi8782 2 หลายเดือนก่อน

    can we upload both images, pdf with separate multer middleware & having both together >? if yes suggest some resources

    • @thedebugarena
      @thedebugarena  หลายเดือนก่อน

      Yes we can upload both images and pdf with separate middleware. You can ask Chat GPT he will provide solution.

    • @rafiuzzamanafridi8782
      @rafiuzzamanafridi8782 หลายเดือนก่อน

      @@thedebugarena ok nice

  • @sanzzz24
    @sanzzz24 4 หลายเดือนก่อน

    Bro i wanna attach image of pdf and pdf itself and display respectively, how do i do it

  • @shankaridurgasree4965
    @shankaridurgasree4965 2 หลายเดือนก่อน

    i couldn't get the folder "files" created after writing the code. How to resolve?

    • @thedebugarena
      @thedebugarena  2 หลายเดือนก่อน +1

      Try manually creating the folder and then upload the image or Dm me on instagram

    • @shankaridurgasree4965
      @shankaridurgasree4965 2 หลายเดือนก่อน

      @@thedebugarena sortedd! Thankyou

  • @hoangng16
    @hoangng16 2 หลายเดือนก่อน

    The physical pdf is actually stored in your server. I suppose it'd be better to place it somewhere online, such as using Firebase or any cloud platform.

    • @thedebugarena
      @thedebugarena  2 หลายเดือนก่อน

      Yes buddy you are correct. When you will host your website you can give path to some folders of your server and this method will work. But this is also good way to store pdf at some cloud platform and then get from there. I will be making video on this also very soon.

    • @hoangng16
      @hoangng16 2 หลายเดือนก่อน

      @@thedebugarena Yeah, thanks for the video. I love to build and share for improvement. My thought on the approach in the video is that it's not scalable.

    • @thedebugarena
      @thedebugarena  2 หลายเดือนก่อน

      @@hoangng16 you are absolutely correct. Thanks for sharing your thoughts.

  • @amal-uz1cj
    @amal-uz1cj 2 หลายเดือนก่อน

    how to take formData on backend side req.file or req. ?

    • @thedebugarena
      @thedebugarena  2 หลายเดือนก่อน

      There are many ways you can take but commonly used method is req.body. if you want more information you can watch first video of this playlist

  • @shahinrohaman6257
    @shahinrohaman6257 2 หลายเดือนก่อน +1

    I got axios network error how can I solve it

    • @thedebugarena
      @thedebugarena  2 หลายเดือนก่อน

      There are many reasons due to which it can occur. First test your api through postman just to be sure that issue is with fronted. If you are not able to solve the issue dm me on instagram @the_debug_arena

    • @tuhinchakroborty5782
      @tuhinchakroborty5782 หลายเดือนก่อน

      Same please help

  • @loopless6248
    @loopless6248 8 หลายเดือนก่อน

    need your help where can we connect

    • @thedebugarena
      @thedebugarena  8 หลายเดือนก่อน

      Dm me on instagram @the_debug_arena

  • @adityaparmar4996
    @adityaparmar4996 6 หลายเดือนก่อน

    if i want to do this for jpg , pdf and docx all then ? let assume that we dont know which type of file user will be upload

    • @thedebugarena
      @thedebugarena  6 หลายเดือนก่อน

      You can just change the file type to all. In input box just give type='file' nothing much then it will accept all types of files.

  • @user-lx5sk8px1j
    @user-lx5sk8px1j 3 หลายเดือนก่อน

    It doesn't work for hosted api bro. It is not a good practice.

    • @thedebugarena
      @thedebugarena  3 หลายเดือนก่อน

      It's should work you will have to modify that properly

  • @amal-uz1cj
    @amal-uz1cj 2 หลายเดือนก่อน

    When i console req.file it shows undefined

    • @thedebugarena
      @thedebugarena  2 หลายเดือนก่อน

      Try req.body and if issue is still there dm me on instagram

    • @amal-uz1cj
      @amal-uz1cj 2 หลายเดือนก่อน

      yes bro still i have problems .i passed the form data to back end but when i console req.body it shows an empty object. But when i console req.file it shows undefined

    • @thedebugarena
      @thedebugarena  2 หลายเดือนก่อน

      @@amal-uz1cj dm me on instagram

    • @amal-uz1cj
      @amal-uz1cj 2 หลายเดือนก่อน

      @@thedebugarena link?

    • @thedebugarena
      @thedebugarena  2 หลายเดือนก่อน

      @@amal-uz1cj the_debug_arena

  • @gautamanand1201
    @gautamanand1201 8 หลายเดือนก่อน +4

    Following the worst practices, don't follow him guys.

    • @thedebugarena
      @thedebugarena  8 หลายเดือนก่อน

      Can you please mention the mistake also

    • @bilalnaeem7158
      @bilalnaeem7158 7 หลายเดือนก่อน

      Reason?

    • @destrobro7044
      @destrobro7044 6 หลายเดือนก่อน

      ​​@@thedebugarena I think he is talking about how you used require instead of using exports and imports, maybe I'm not sure.
      A good video nonetheless 👍

    • @thedebugarena
      @thedebugarena  6 หลายเดือนก่อน

      @@destrobro7044 yes that's another way to import will use that In some other video.

    • @josteins4501
      @josteins4501 3 หลายเดือนก่อน

      @@thedebugarena Your logic is pretty good but the thing you are missing are proper file structure and and proper seperation of logic. You could have easily broken down your code into more manageable components.(That's what react helps the most with) cheers !! Great effort !!