我正在使用来自phonegap的javascript从ios图库上传图片。图像上传正常,但图像已损坏。
以下是代码:
<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);
}
}