ng-file-upload无法在Ionics中上传 [英] ng-file-upload not uploading in Ionics
问题描述
我正在使用 ng-file-upload 我的Ionic移动应用程序的库,我在实现这个库时遇到了挑战。我还将Codeigniter用于我的REST API。我的上传请求应包含字段(某些数据)和图像。这是我到目前为止的代码:
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);
})
};
这已经连接到一个按钮,但每次按下按钮,都没有任何反应,在日志中文件我收到错误0。
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)
======编辑2 =======
======EDIT 2=======
我现在有来自服务器的响应,我输入了错误的网址。但现在问题是我无法在我的codeigniter后端解析$ _FILES中的响应。我var_dump它,这是响应:
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.
谢谢
推荐答案
根据这个问题,你不能在Cordova上使用ng-file-upload。相反,你必须使用< a href =https://github.com/apache/cordova-plugin-file-transfer =nofollow> cordova-plugin-file-transfer ,如果你愿意,它的 ng-cordova适配器。
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.
这篇关于ng-file-upload无法在Ionics中上传的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!