How I Can Convert JSON into Form Data
let data = {
image : this.state.file,
title : this.state.title,
description: this.state.description,
}
How I Can Convert JSON into Form Data
let data = {
image : this.state.file,
title : this.state.title,
description: this.state.description,
}
Try this way
let data = `{
"image": ${this.state.file},
"title" : ${this.state.title},
"description": ${this.state.description},
}`;
const jsonData = JSON.parse(data);
var fdata = new FormData();
fdata.append('image', {
uri: jsonData.image,
name: 'photo.jpeg',
type: 'image/jpeg'
});
fdata.append('title',jsonData.title);
fdata.append('description',jsonData.description);
Something like this:
let form_data = new FormData();
form_data.set('data', {
"image": this.state.file,
"title" : this.state.title,
"description": this.state.description,
});
ax({
url: '/api',
method: 'post',
data: form_data,
headers: {'content-type': 'multipart/form-data'}
})
.then(response => {
})
.catch(error => {
});