In Ionic 4 angular 7 application trying to upload an image from the Cordova camera plugin.
The output from the Camera plugin is base64 image data.
this.camera.getPicture(options).then((imageData) => {
// imageData is 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) => {
// Handle error
});
I am generating an AWS S3 pre-signed URL to upload an Image on server side.
Below code does not give any error, but the uploaded image is just a black screen and not the actual image.
What is the correct way to HTTP PUT an Image to S3, the available image 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();
}