I'm building an app with Ionic 2. I need to take a photo from gallery or camera and upload this picture to my server. I have this code that opens the Gallery and takes a picture.
accessGallery() {
this.camera.getPicture({
sourceType: this.camera.PictureSourceType.SAVEDPHOTOALBUM,
destinationType: this.camera.DestinationType.DATA_URL
}).then((imageData) => {
this.base64Image = 'data:image/jpeg;base64,' + imageData;
this.uploadFile();
}, (err) => {
console.log(err);
});
}
upload image to server side
uploadFile() {
let body = new FormData();
body.append('images', this.base64Image);
let headers = new Headers({
'token': this.token,
'sid': this.sid,
'user': this.user,
'to': this.to,
'node': this.node,
'type':'image'
});
let options = new RequestOptions({ headers: headers });
console.log("header ----" +JSON.stringify(headers));
console.log("images data body----" +JSON.stringify(body));
this.http.post(this.apiurl,body,options)
.map(res => res.json())
.subscribe(
data => {
console.log(data);
},
err => {
console.log("ERROR!: ", err);
}
);
}
ERROR :- Field value too long