I want to upload several images to my server nodejs that have additional information such as title and category , I tried sending the images in DataUrl but due to The limitations of POST does not allow me to upload more than 2 images at a time.
To load the images I use this reagent component Component to load images that has the method handleSubmitImages to send the status of the component to the server using ajax.
handleSubmitImages ()
handleSubmitImages(){
let xhr = new XMLHttpRequest()
let json = JSON.stringify({images: this.state.images})
xhr.open("POST",'new',true)
xhr.setRequestHeader("Content-Type","application/json")
xhr.send(json)
}
Component status
The state of the component is formed by an array of json objects that contain the information of the images as follows:
[
{ title: 'Imagen 264',
file: [Blob], // Este es el blob del archivo
data: 'data:image/jpeg;base64,/9j/4AAQSkZJRgA', //Imagen en base64
category: 1 }
]
On the server I have the route wallpapers / new to upload images using the POST method.
Route wallpapers / new
router.route("/new")
.get(function(req,res){
res.render('wallpaper/new',{
user: req.user
})
})
.post(function(req, res) {
let images = req.body.images
images.map(image => {
// Aquí debería poder guardar la imagen en mi servidor
})
});
NOTE: I've read tutorials that use formidable and FormData () to upload multiple images at once but none of them They send additional information such as the title of the image or something similar. I hope you can help me.