我收到JAVA.io.IOException收到服务器错误。以下是从phonegap app上传文件到amazon s3的代码。
我跟随此链接的示例:
http://coenraets.org/blog/2013/09/how-to-upload-pictures-from-a-phonegap-app-to-amazon-s3/
var s3Uploader =(function(){
var s3URI = encodeURI("http://***********.s3-website-us-west-2.amazonaws.com/");
policyBase64 = "base64 string removed";
signature = "base64 string removed";
awsKey = 'AWSAccessKeyId removed';
acl = "public-read";
function upload(imageURI, fileName) {
var deferred = $.Deferred()
var ft = new FileTransfer();
options = new FileUploadOptions();
options.fileKey = "file";
options.fileName = fileName;
options.mimeType = "image/jpeg";
options.chunkedMode = true;
options.params = {
"key": fileName,
"AWSAccessKeyId": awsKey,
"acl": acl,
"policy": policyBase64,
"signature": signature,
"Content-Type": "image/jpeg"
};
ft.upload(imageURI, s3URI,
function (e) {
console.log(e);
deferred.resolve(e);
},
function (e) {
console.log(JSON.stringify(e));
deferred.reject(e);
}, options);
return deferred.promise();
}
return {
upload: upload
}
}());
var $ img = $(' img',' .scroller');
takePicture = function (e) {
var options = {
quality: 45,
targetWidth: 1000,
targetHeight: 1000,
destinationType: Camera.DestinationType.FILE_URI,
encodingType: Camera.EncodingType.JPEG,
sourceType: Camera.PictureSourceType.PHOTOLIBRARY
};
navigator.camera.getPicture(
function (imageURI) {
alert(imageURI);
alert(imageURI);
$img.attr('src', imageURI);
var fileName = "" + (new Date()).getTime() + ".jpg";
s3Uploader.upload(imageURI, fileName)
.done(function () {
alert("S3 upload succeeded");
})
.fail(function () {
alert("S3 upload failed");
});
},
function (message) {
alert(JSON.stringify(message));
}, options);
return false;
};
$('.camera-btn').on('click', takePicture);