const options: CameraOptions = {
quality: 100,
correctOrientation: true,
destinationType: this.camera.DestinationType.FILE_URI,
encodingType: this.camera.EncodingType.JPEG,
mediaType: this.camera.MediaType.PICTURE,
sourceType: sourceType
}
// Get the picture
this.camera.getPicture(options).then((imageData) => {
console.log(imageData);
let loading = this.loadingCtrl.create();
loading.present();
// Resolve the picture URI to a file
this.file.resolveLocalFilesystemUrl(imageData).then(oneFile => {
// Convert the File to an ArrayBuffer for upload
this.file.readAsArrayBuffer(this.file.applicationDirectory, oneFile.name).then(realFile => {
let type = 'jpg';
let newName = this.awsProvider.randomString(6) + new Date().getTime() + '.' + type;
// Get the URL for our PUT request
this.awsProvider.getSignedUploadRequest(newName, 'image/jpeg').subscribe(data => {
let reqUrl = data.signedRequest;
// Finally upload the file (arrayBuffer) to AWS
this.awsProvider.uploadFile(reqUrl, realFile).subscribe(result => {
// Add the resolved URL of the file to our local array
this.awsProvider.getSignedFileRequest(newName).subscribe(res => {
this.images.push({key: newName, uri: res});
loading.dismiss();
});
});
});
});
}, err => {
console.log('err: ', err);
})
}, (err) => {
console.log('err: ', err);
});
}
Some who knows how to upload image file from local file directory? I have follow the tutorial from https://devdactic.com/ionic-aws-nodejs-2/ .
Error ( err: DOMException: A URI supplied to the API was malformed, or the resulting Data URL has exceeded the URL length limitations for Data URLs.)