I am creating an application with Ionic 2. I need to take a photo from a gallery or camera and upload this picture to my server. I have this code that opens a 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
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 is too long
source share