ng-file-upload not uploading in Ionics

℡╲_俬逩灬. 提交于 2019-12-22 11:19:33

问题


I am using ng-file-upload library for my Ionic mobile application and Im having challenges in implementing this library. I also used Codeigniter for my REST API. My upload request should have fields(some data) and the images. here is my code so far:

$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);
    })
};

This is already connected to a button, but everytime I press the button, nothing happens, In the log file i get error 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)

======EDIT 2=======

I now have a response from the server, i inputed the wrong url. But the problem now is I cant parse the reponse in $_FILES in my codeigniter backend. I var_dump it and here is the response:

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)

Looking forward for your help,I cant figure out what im missing.

Thanks


回答1:


According to this issue on the repo, you can't use ng-file-upload with Cordova. Instead, you have to use cordova-plugin-file-transfer and, if you want, its ng-cordova adapter.



来源:https://stackoverflow.com/questions/32336171/ng-file-upload-not-uploading-in-ionics

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!