I am using javascript from phonegap to upload an image from ios gallery. the image upload goes fine but the image is corrupted.
Here is the code:
<script src="https://sdk.amazonaws.com/js/aws-sdk-2.1.12.min.js"></script>
<script type="text/javascript">
app.initialize();
var imgData = null;
function uploadToS3(imageData) {
var imgData = getImgData(imageData);
var key = 'SOME_IMAGE_NAME.jpg';
AWS.config.update({accessKeyId: 'XXX', secretAccessKey: 'XXX', region:'us-west-1'});
var bucket = new AWS.S3({params:{Bucket: 'mybucket'}});
var params = {
Key: key,
Body: imageData,
ACL: 'public-read',
ContentType: 'image/jpeg'
};
bucket.upload(params, function(err, data) {
alert(data.Location);
});
}
function getImage() {
navigator.camera.getPicture(onSuccess, onFailure, { navigator.camera.getPicture(onSuccess, onFailure, {quality: 25,
destinationType: navigator.camera.DestinationType.DATA_URL,
sourceType: navigator.camera.PictureSourceType.PHOTOLIBRARY
});
function onSuccess(imageURI) {
var imgData = "data:image/jpeg;base64," + imageURI;
uploadToS3(imgData);
}
function onFailure(message) {
alert("Get image failed: " + message);
}
}