I am trying to upload an image (as base64 format) from phone gap application to amazon s3. The image is uploaded successfully, but it's displayed as boxes when I try to view the image in Amazon server. I used the below link for my reference.
Uploading image to S3 using phonegap, how to?
I also tried to upload the image (as imageURI) using the below link, but it throws an error Body.params is required
https://github.com/ccoenraets/phonegap-s3-upload/blob/master/client/phonegap-s3-upload/www/app.js
Please find the snippets of code,
// take picture
var options = {
quality: 75,
targetWidth: 320,
targetHeight: 320,
destinationType: 1, // 0 = base 64, 1 = imageURI
sourceType: 1, // 0:Photo Library, 1=Camera, 2=Saved Photo Album
encodingType: 0 // 0=JPG 1=PNG
};
// Take picture using device camera and retrieve image as base64-encoded string
navigator.camera.getPicture(onSuccess,onFail,options);
---------
uploading the image
var imageData = 'data:image/jpeg;base64,'+ $scope.lastPhoto;
var params = {
Key: 'test5.jpg', // for testing purpose
Body: imageData, // base64 data
ContentEncoding: 'base64',
ContentType: 'image/jpeg'
};
var fileName = "" + (new Date()).getTime() + ".jpg";
console.log ('data params' + params.Body);
bucket.upload(params, function(err, data){
$scope.hide($ionicLoading);
var result = err ? 'ERROR!' : 'UPLOADED SUCCESSFULLY...';
var alertPopup = $ionicPopup.alert({
title: 'Amazon Confirmation',
template: 'Result : ' + result
});