Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

144
Views
What is the best way to send both Image and JSON to my express server?

Ok, so I got a mongodb database, and I am using mongoose.

I have the following model for my product.

const productSchema = new Schema({
  name: { type: String, required: true},
  description: { type: String, required: true },
  price: { type: Number, required: true },
  image: { type: String, required: true },
  
  usage: { type: String, required: true },
  species: [{
    specie: { type: String, required: true }
  }],
  ingredients: [{
    name: { type: String, required: true },
    quantity: { type: String, required: true },
  }],
});

What I am trying to do is send both an image and JSON in a SINGULAR http request. I found out that this is not really possible. So what is the best to achieve this? Send two different HTTP requests, one with the json/text data, and one with the file? This would mean that I need to edit my model and make the fields unrequired, and it would be a bit rough to debug in case something goes wrong with one of the requests.

  const newProduct = {
        name: name,
        description: description,
        price: price,
        usage: usage,
        ingredients: itemList,
        species: speciesList,
        image: image,
      };


     const [itemList, setItemList] = useState([
    { name: "", quantity: "" },
  ]);
  const [speciesList, setSpeciesList] = useState([
    { specie: "" },
  ]);

This is what I am trying to send

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

It's simple. you can send the data to the express server with multipart/form-data structure and then in the server should parse received data and map the values as defined model and finally store into mongo db.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!