phonegap解析为后端以保存相机图片无法正常工作

时间:2016-01-03 07:41:25

标签: javascript cordova parse-platform

app.js



document.addEventListener("deviceready", init, false);
Parse.initialize("Bsx4lKtDVM36WIXgtrh3VElVNkJb9MRi6VJ8zl5L", "obSiqq5y7GV1SHfRveojFv5HllO3EJcdf0iValSl");
function init() {


    //Use from Camera
   
    //Use from Library
    document.querySelector("#usePicture").addEventListener("touchend", function() {
        navigator.camera.getPicture(gotPic, onFail, { 
            quality: 50,
            sourceType: Camera.PictureSourceType.PHOTOLIBRARY,
            destinationType: Camera.DestinationType.FILE_URI
        });

    });

    
    function gotPic(data) {
       var parseFile = new Parse.File("mypic.jpg", {base64:data});
            parseFile.save().then(function() {
                navigator.notification.alert("Got it!", null);
                console.log("Ok");
                console.log(arguments.toString());
            }, function(error) {
                console.log("Error");
                console.log(error);
            });
        
    }

    function onFail(message) {
        alert('Failed because: ' + message);
    }   

}

<html>
    <head>
        <meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
        <title></title>
        <meta name="description" content="">
        <meta name="viewport" content="width=device-width">
        <link rel="stylesheet" type="text/css" href="css/app.css" />
        <style>
        button {
            width: 90%;
        }
        body {
            margin-top: 50px;
        }
        img {
            max-width: 100%;
            max-height: 250px;
        }
        </style>
    </head>
    <body>

    <img id="myImage">

    <button id="usePicture">Use Picture</button>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js"></script>
<script type="text/javascript" src="http://www.parsecdn.com/js/parse-1.2.15.min.js"></script>
    <script src="cordova.js"></script>  
    <script src="js/app.js"></script>
    </body>
</html>
&#13;
&#13;
&#13;

上面的代码是main.html文件问题,当我在手机上运行应用程序时,我可以点击按钮并从图库中选择图像,但之后它无法上传到解析而且没有成功的消息回复你们可以帮我解决一下是什么问题

0 个答案:

没有答案