So after many hours of searching , it’s very important to import formdata
import FormData from 'form-data'
Then it work
async enregistreAjout() {
try {
await axios.post(`${constantes.serveurapi}/${constantes.collectionAnnonces}`, {
title: this.titre,
category: this.categorie,
content: this.commentaire
}, {
headers : {
'content-type': 'application/json',
'Authorization': 'Bearer ' + this.token
}
})
.then((response) => {
let formData = new FormData() // /!\ on doit importer Formdata sinon erreur 400 bad request
formData.append("files",this.file) // quel est le fichier
formData.append("ref","annonce") // quel est la collection (sans le s à la fin)
formData.append("refId",response.data.id)// quel est l'id
formData.append("field","picture")//quel est le champ
return axios.post(`${constantes.serveurapi}/upload`,
formData
,{
headers : {
'Authorization': 'Bearer ' + this.token
}
})
})
} catch(error) {
console.error(error)
}
}