Ionic v2, Android
Trying to upload an image take with the camera to a server but cant find image path.
.ts file:
public takePicture(){
const options: CameraOptions = {
quality: 100,
destinationType: this.camera.DestinationType.DATA_URL,
encodingType: this.camera.EncodingType.JPEG,
mediaType: this.camera.MediaType.PICTURE,
allowEdit: true
}
this.camera.getPicture(options).then((imageData) => {
this.base64Image = 'data:image/jpeg;base64,' + imageData;
this.photo = this.base64Image;
this.imageURL = this.filePath.resolveNativePath(this.base64Image);
}, (err) => {
// Handles error
});
public uploadImage(photo) {
// File name only
// var filename = "photo";
// File for Upload
var targetPath = cordova.file.externalDataDirectory;
var url = "http://127.0.0.1:8000/upload/";
var options = {
httpMethod: 'POST',
chunkedMode: false,
};
const fileTransfer: FileTransferObject = this.transfer.create();
this.loading = this.loadingCtrl.create({
content: 'Uploading...',
});
this.loading.present();
// Use the FileTransfer to upload the image
fileTransfer.upload(this.imageURL, url, options).then(data => {
this.loading.dismissAll()
this.presentToast('Image succesful uploaded.');
}, err => {
this.loading.dismissAll()
this.presentToast('Error while uploading file.');
});
}
trying to upload to a REST server!
any idea where i might be screwing up?