Is it possible in IONIC-2 to upload image and include form data ie Username etc to the php on remote server on upload. ‘without using Base64 Image’
I use this to post an imagefile to my server. I think you can append more form data without problems.
avatar is the image file.
async uploadAvatar(token: string, avatar: File): Promise<Profile> {
try {
let headers = new Headers({ 'x-auth': token });
let formData = new FormData();
formData.append('avatar', avatar, avatar.name);
const response = await this.http.post(`${this.server}${this.profilesAvatarsRoute}`, formData, { headers: headers }).toPromise();
this.userProfile = response.json().profile;
if (this.userProfile.avatar) {
this.userProfile.avatar = await this.getUserAvatarBase64(token);
}
return this.userProfile;
} catch (err) {
throw new Error(err.status + " - " + err.statusText);
}
}