PhoneGap文件上传3G

时间:2013-05-09 16:12:32

标签: cordova file-upload upload 3g

我目前正在遇到一个非常恼人的PhoneGap问题。我创建了一个将图像上传到远程服务器的应用程序(服务器运行PHP)。

当我通过WiFi上传图像时,该应用程序运行正常,但当我通过2G / 3G上传相同的图像时没有任何反应。没有错误回调,没有成功回调,没有任何反应。

我尝试过不同的文件大小,包括一些非常小的(~150kb)文件,这似乎没有帮助/重要。我尝试过Cordova版本2.5,2.6和2.7。该应用程序使用phonegap文档中的默认示例。应用代码为:

var app = {
    // Application Constructor
    initialize: function() {
        this.bindEvents();
    },
    // Bind Event Listeners
    //
    // Bind any events that are required on startup. Common events are:
    // 'load', 'deviceready', 'offline', and 'online'.
    bindEvents: function() {
        document.addEventListener('deviceready', this.onDeviceReady, false);
    },
    // deviceready Event Handler
    //
    // The scope of 'this' is the event. In order to call the 'receivedEvent'
    // function, we must explicity call 'app.receivedEvent(...);'
    onDeviceReady: function() {
        app.receivedEvent('deviceready');
    },
    // Update DOM on a Received Event
    receivedEvent: function(id) {
        var parentElement = document.getElementById(id);
        var listeningElement = parentElement.querySelector('.listening');
        var receivedElement = parentElement.querySelector('.received');

        listeningElement.setAttribute('style', 'display:none;');
        receivedElement.setAttribute('style', 'display:block;');

        console.log('Received Event: ' + id);
    },

    doStuff: function() {
        navigator.camera.getPicture(app.uploadPhoto,
                                        function(message) { alert('get picture failed'); },
                                        { quality: 50,
                                        destinationType: navigator.camera.DestinationType.FILE_URI,
                                        sourceType: navigator.camera.PictureSourceType.PHOTOLIBRARY }
                                        );
    },

    uploadPhoto: function(imageURI) {
        var options = new FileUploadOptions();

        options.fileKey="files";
        options.fileName=imageURI.substr(imageURI.lastIndexOf('/')+1);
        options.mimeType="image/jpeg";

        var params = {};
        params.pathname = "VARIABLE_FOR_SERVER";
        params['file-type'] = 'image';

        options.params = params;

        try {
            var ft = new FileTransfer();
            ft.upload(imageURI, encodeURI("SERVER_URL_HERE"), app.win, app.fail, options, true);
        } catch (err) {
            console.log('catch error');
            console.log(err);
        }
    },

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

    fail: function(error) {
        alert("An error has occurred: Code = " + error.code);
        console.log("upload error source " + error.source);
        console.log("upload error target " + error.target);
    }

};

在服务器上,$ _FILES变量为空。有没有人知道这里发生了什么,因为我疯狂地试图修复/调试这个:D

0 个答案:

没有答案
相关问题