Hi,
i am uploading the image to server, getting error code=1 and error code=2, with server response 400, and 500.
i followed this tutorial http://www.developerslearnit.com/2016/11/build-photo-gallery-app-with-ionic2.html
Image path:
file:///storage/emulated/0/Android/data/com.ionicframework.roadrunner267118/IMG_20161123_125005.jpg
image picker:
ImagePick() {
var options: any;
options = {
quality: 75,
destinationType: Camera.DestinationType.FILE_URI,
sourceType: Camera.PictureSourceType.PHOTOLIBRARY,
encodingType: Camera.EncodingType.JPEG,
targetWidth: 500,
targetHeight: 500,
saveToPhotoAlbum: false
};
Camera.getPicture(options).then((imgUrl) => {
var sourceDirectory = imgUrl.substring(0, imgUrl.lastIndexOf('/') + 1);
var sourceFileName = imgUrl.substring(imgUrl.lastIndexOf('/') + 1, imgUrl.length);
sourceFileName = sourceFileName.split('?').shift();
File.copyFile(sourceDirectory, sourceFileName, cordova.file.externalApplicationStorageDirectory, sourceFileName).then((result: any) => {
this.imagePath = imgUrl;
this.imageChosen = 1;
this.imageNewPath = result.nativeURL;
}, (err) => {
alert(JSON.stringify(err));
})
}, (err) => {
alert(JSON.stringify(err))
});
}
**Here is upload code:**
// options:
let filename = this.imagePath.split('/').pop();
let options = {
fileKey: "file",
fileName: filename,
chunkedMode: false,
mimeType: "image/jpg",
params: { 'email': this.myForm.controls.email.value, 'password': this.myForm.controls.password.value, 'password_confirmation':
this.myForm.controls.password_confirmation.value, 'first_name': this.myForm.controls.first_name.value, 'last_name':this.myForm.controls.last_name.value,
'address': this.myForm.controls.address.value, 'city_id': this.myForm.controls.city_id.value, 'phone': this.myForm.controls.phone.value
},
headers: {"Content-Type": "application/json"}
};
// image upload
const fileTransfer = new Transfer();
fileTransfer.upload(this.imageNewPath, URL,
options).then((entry) => {
this.imagePath = '';
this.imageChosen = 0;
this.navCtrl.setRoot(LoginPage);
}, (err) => {
alert(JSON.stringify(err));
});
please guide me where i am doing wrong…
Thanks!