Phonegap Filetransfer适用于iOS在Android上没有任何反应

时间:2014-10-08 13:34:40

标签: android ios cordova file-transfer

现在,我在服务器上上传一些图片时遇到问题。我的代码在iOS设备上完美运行,但是当我尝试在Android上传时,它只是没有做任何事情。在文件传输之前,我正在尝试提醒ImageURI,但它也没有发生。

我正在使用PhoneGap Build with Phonegap 3.4.0版和Sencha Touch 2.3。在config.xml中,我使用核心phonegap相机插件:<gap:plugin name="org.apache.cordova.camera" />.

我的fileupload脚本如下所示:

Ext.define('my_app.controller.Fileupload', {
    extend: 'Ext.app.Controller',
    requires: [
        'Ext.MessageBox'
    ],
    config: {
        refs: {
            fileupload: '#fileupload',
            getLibraryImage: 'button[action=getLibraryImage]',
            getCameraImage: 'button[action=getCameraImage]'
        },
        control: {
            getLibraryImage: {
                tap: 'getLibraryImage'
            },
            getCameraImage: {
                tap: 'getCameraImage'
            }
        }
    },
    getLibraryImage: function() {

        navigator.camera.getPicture(this.fileupload, onFail, {
            destinationType: Camera.DestinationType.FILE_URI,
            sourceType: Camera.PictureSourceType.PHOTOLIBRARY,
            allowEdit: true,
            targetWidth: 800,
            targetHeight: 800
        });

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

    },
    getCameraImage: function() {

        navigator.camera.getPicture(this.fileupload, onFail, {
            destinationType: Camera.DestinationType.FILE_URI,
            sourceType: Camera.PictureSourceType.CAMERA,
            quality: 100,
            allowEdit: true,
            targetWidth: 800,
            targetHeight: 800
        });

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

    },
    fileupload: function(imageURI) {

    alert(imageURI);

        Ext.Viewport.setMasked({
            xtype: 'loadmask',
            message: Loc.t('LOADMASK.FILEUPLOAD'),
            styleHtmlContent: true,
            indicator: true
        });

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

//  if (Ext.os.is('Android')) {
//      options.chunkedMode = true;
//  }

        var user = JSON.parse(localStorage.getItem('user'));

        var user_id = user.id;
        var username = user.username;

        var params = new Object();
        params.user_id = user_id;
        params.username = username;
        options.params = params;

        var ft = new FileTransfer();
        ft.upload(imageURI, encodeURI("my_upload_uri"), win, fail, options);

        function win(response) {

            if (Ext.JSON.decode(response.response).error) {

                Ext.Viewport.setMasked(false);
                Ext.Msg.alert('my_app', Ext.JSON.decode(response.response).error);

            } else {


                my_app.app.getController('Basic').ProfileImages();
                Ext.Msg.alert('my_app', Ext.JSON.decode(response.response).success);


            }


        }

        function fail(error) {

            Ext.Viewport.setMasked(false);

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

    }
});

如果有人能看到问题,我真的很感激帮助!提前谢谢。

1 个答案:

答案 0 :(得分:0)

升级到PhoneGap 3.6.3版本解决了我的问题。