phonegap到亚马逊S3上传的图片已损坏

时间:2017-03-29 05:22:40

标签: javascript cordova amazon-web-services amazon-s3 phonegap-plugins

我正在使用来自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);
                }
        }

0 个答案:

没有答案