multer I can't display my react app images

Issue

Hello my problem is that I use multer to store them on my server and their path on mongodb, but I can’t get them to display on my react application.

thanks in advance for all the help.

Solution

You need to send the data from React in FormData, example:

Node

import multer from "multer" // const multer = require("multer")
const upload = multer()
// in your route
app.post("/any-route", upload.array("name_id", 10), () => {
    let file = null
    if (req.files && req.files.lenght > 0){
     file = req.file[0]
    }
   // and this file you can send to MongoDB
})

In react you need use FormData

const FormData = new FormData()
FormData.append("name_id", file) // this file is the file you want send

Answered By – Sebastian Melendez

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published