构建后的phonegap上传问题

时间:2013-03-08 15:17:59

标签: cordova

    function getImage() {
        Retrieve image file location from specified source
        navigator.camera.MediaType.ALLMEDIA
        navigator.camera.getPicture(uploadPhoto, function(message) {
        alert('File Not Selected');
    },{
        quality: 50, 
        destinationType: navigator.camera.DestinationType.FILE_URI,
        sourceType: navigator.camera.PictureSourceType.PHOTOLIBRARY,
        mediaType: navigator.camera.MediaType.ALLMEDIA
    }
        );

    }

    function uploadPhoto(imageURI) {
        var options = new FileUploadOptions();
        options.fileKey="uploaded";
        options.fileName=imageURI.substr(imageURI.lastIndexOf('/')+1);
        options.mimeType="image/jpeg";

        var params = new Object();
        params.value1 = "test";
        params.value2 = "param";

        options.params = params;
        options.chunkedMode = false;

        var ft = new FileTransfer();
        ft.upload(imageURI, "abc.php", win, fail, options);
    }

    function win(r) {
        console.log("Code = " + r.responseCode);
        console.log("Response = " + r.response);
        console.log("Sent = " + r.bytesSent);
        alert(r.response);
    }

    function fail(error) {
        alert("An error has occurred: Code = " +error.code);
    }

这可以通过eclipse在Android模拟器上正常工作。按下上传按钮并要求上传文件;当apk文件由设备上没有上传按钮工作的phonegap创建时,它会失败。我还要删除phonegap.js。

2 个答案:

答案 0 :(得分:0)

相机插件是否已添加到config.xml?

<plugin name="Camera" value="org.apache.cordova.CameraLauncher" />

答案 1 :(得分:0)

你说你必须删除phonegap.js?

如果您这样做,则无法访问任何设备API,因为它们依赖于应用程序中特定于设备的phonegap.js。这将在构建时注入PhoneGap Build。