Within my Ionic 4 Angular 7 application, I am attempting to upload an image captured using the Cordova camera plugin.
The output data from this Camera plugin is in the form of base64 image data.
this.camera.getPicture(options).then((imageData) => {
// imageData can be either a base64 encoded string or a file URI
// If it's base64 (DATA_URL):
const base64Image = 'data:image/jpeg;base64,' + imageData;
this.uploadImage(url, base64Image )
}, (err) => {
// Handling any errors that may occur
});
To achieve this, I am generating a pre-signed AWS S3 URL for uploading images on the server.
For example
The current code does not throw any errors, but after uploading, the image displayed is just a black screen instead of the actual image.
I am looking for the correct method to perform an HTTP PUT request to S3 with the available image content in base64 encoded format.
uploadImage(url: string, imageData: any): Promise<any> {
const headers = new HttpHeaders({'Content-Type': 'image/jpeg;'});
return this.http.put(url, imageData, {headers: headers})
.pipe(
tap(data => console.log(JSON.stringify(data))),
catchError(this.handleError('uploadImage'))
).toPromise();
}