ng-file-upload无法在Ionics中上传

时间:2015-09-01 16:01:42

标签: php angularjs codeigniter ionic-framework ng-file-upload

我正在为我的Ionic移动应用程序使用ng-file-upload库,我在实现此库时遇到了挑战。我还将Codeigniter用于我的REST API。我的上传请求应该有字段(一些数据)和图像。这是我目前的代码:

$scope.doSubmitAttachment = function(){
    console.log('@@@@@doSubmitAttachement- Process Request--' + $scope.images);
    $scope.upload($scope.images);
    };



$scope.upload = function (file) {
    Upload.upload({
        url: 'http://192.168.8.247:130/api/upload',
        fields: {'username': 'juan'},
        file: file
    }).progress(function (evt) {
        var progressPercentage = parseInt(100.0 * evt.loaded / evt.total);
        console.log('progress: ' + progressPercentage + '% ' + evt.config.file.name);
    }).success(function (data, status, headers, config) {
        console.log('file ' + config.file.name + 'uploaded. Response: ' + data);
    }).error(function (data, status, headers, config) {
        console.log('error status: ' + status);
    })
};

这已经连接到一个按钮,但每次按下按钮时都没有任何反应,在日志文件中我收到错误0。

09-01 11:56:07.726  11315-11315/com.ionicframework.myapp I/chromium﹕ [INFO:CONSOLE(173)] "@@@@@doSubmitAttachement- Process Request--file:///data/data/com.ionicframework.myapp/cache/maxresdefault1914240190.jpg", source: file:///android_asset/www/plugins/cordova-plugin-console/www/console-via-logger.js (173)

09-01 11:58:14.906  11315-11315/com.ionicframework.myapp I/chromium﹕ [INFO:CONSOLE(173)] "error status: 0", source: file:///android_asset/www/plugins/cordova-plugin-console/www/console-via-logger.js (173)

09-01 13:16:09.602    1541-1541/com.ionicframework.mase101409 I/chromium﹕ [INFO:CONSOLE(173)] "error data: null", source: file:///android_asset/www/plugins/cordova-plugin-console/www/console-via-logger.js (173)

09-01 13:16:09.602    1541-1541/com.ionicframework.mase101409 I/chromium﹕ [INFO:CONSOLE(173)] "error config: [object Object]", source: file:///android_asset/www/plugins/cordova-plugin-console/www/console-via-logger.js (173)

09-01 13:16:09.606    1541-1541/com.ionicframework.mase101409 I/chromium﹕ [INFO:CONSOLE(173)] "error headers: function (name) {
if (!headersObj) headersObj =  parseHeaders(headers);
if (name) {
var value = headersObj[lowercase(name)];
if (value === void 0) {
value = null;
}
return value;
}
return headersObj;
}", source: file:///android_asset/www/plugins/cordova-plugin-console/www/console-via-logger.js (173)

======编辑2 =======

我现在收到服务器的回复,我输入了错误的网址。但现在的问题是我无法在我的codeigniter后端解析$ _FILES中的响应。我var_dump它,这是响应:

09-01 23:13:59.801    5236-5236/com.ionicframework.mase101409 I/chromium﹕ [INFO:CONSOLE(173)] "file uploaded. Response: array(0) {
}
", source: file:///android_asset/www/plugins/cordova-plugin-console/www/console-via-logger.js (173)

期待你的帮助,我无法弄清楚我失踪了什么。

由于

1 个答案:

答案 0 :(得分:1)

根据repo上的this issue,你不能在Cordova上使用ng-file-upload。相反,您必须使用cordova-plugin-file-transfer,如果需要,还必须使用ng-cordova adapter