I want to send an image as a file to the server in react native. How can I do this? Here is my code:-
export const editUserProfile = (sessionId,firstName,lastName,image,countryCode,phone) =>
new Promise((resolve,reject) => {
const form = new FormData();
form.append('image',{
uri : image,
type : 'image/jpeg',
name : 'image.jpg'
})
return axios.post(base_url+'edit-profile',{
session_id : sessionId,
firstname : firstName,
lastname : lastName,
image : null,
country_code : countryCode,
phone : phone,
locale : 'en'
}).then(response =>
{resolve(response)})
.catch(error =>
{reject(error)});
});
//edit user profile
export const editUserProfile =
(sessionId,firstName,lastName,image,countryCode,phone) =>
new Promise((resolve,reject) => {
var data = new FormData();
data.append('session_id',sessionId);
data.append('firstname',firstName);
data.append('lastname',lastName);
data.append('image',
{
uri:image,
name:'userProfile.jpg',
type:'image/jpg'
});
data.append('country_code',countryCode);
data.append('phone',phone);
data.append('locale','en');
return axios.post(base_url+'edit-profile',data).then(response =>
{resolve(response)})
.catch(error =>
{reject(error)});
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With