I am performing an update where, in addition to other data, I need to send Node an array that includes the information of one or more images, but only their path and ID, not the image itself.
I am performing an update where, in addition to other data, I need to send Node an array that includes the information of one or more images to be deleted, but I only pass its path as well as ID, not the image itself since the images are in Cloudinary.
I use formData because among these data I send the new images in case new ones are required, but I receive all the data except for the images to be deleted, since instead of receiving an array I only receive [Object Object] and I cannot work with it. This is my code:
const putProduct = async (productToUpdate, filesToDelete) => {
console.log(filesToDelete) // Array
const formData = new FormData()
const imageArr = Array.from(productToUpdate.pictures)
imageArr.forEach(image => {
formData.append('pictures', image)
})
formData.append('filesToDelete', filesToDelete)
formData.append('barCode', productToUpdate.barCode)
try {
const dataOnLs = localStorage.getItem('cmtjs')
const config = {
headers: {
"Content-Type": "multipart/form-data",
apiKey: dataOnLs
}
}
const { data } = await axiosClient.put(`/products/${productToUpdate.id}`, formData, config )
I receive in Node and go through the console req.body.filesToDelete but it always indicates [Object Object]
let updateProduct = async ( req, res = response ) => {
const filesToDelete = req.body.filesToDelete;
console.log(filesToDelete); // [object Object]
return