Я новичок в React Native и Strapi, и я хочу загружать изображения в API: мое приложение позволяет пользователю добавлять объявление о продаже (название, описание, количество, количество лотов, цена, фото 1, фото 2, .. .).
Я могу добавить объявление о продаже с текстовыми полями, но не с фотографиями. И я не могу найти, как это сделать, в документе Strapi (я использую MongoDB). Зная, что Strapi не принимает FormData. На данный момент я получаю изображение смартфона в формате base64 и отправляю его в API, но это не работает.
Insert_Into_DataBase = () => {
console.log("insert");
console.log(this.state.image1);
this.setState(
{
ActivityIndicator_Loading: true
},
() => {
console.log("fetch");
fetch("http://192.168.0.102:1337/annonces", {
method: "POST",
headers: {
"Content-Type": "application/json"
},
body: JSON.stringify({
titreAnnonce: this.state.titre,
description: this.state.description,
qte: this.state.disponibilite,
nbrLots: this.state.lots,
Image1: this.state.image1
})
})
.then(response => response.json())
.then(responseJsonFromServer => {
alert(responseJsonFromServer + "L'annonce à bien été postée");
this.setState({ ActivityIndicator_Loading: false });
})
.catch(error => {
console.error(error);
this.setState({ ActivityIndicator_Loading: false });
});
}
);
};