使用ngCordova进行文件上传时的异常情况

时间:2016-10-08 20:02:24

标签: angularjs cordova asp.net-web-api ngcordova

我正在使用带有后端服务器的cordova在Asp.net上编写的跨平台移动应用程序 我想使用REST api从应用程序上传文件到服务器 。我只想检查是否使用断点调用该方法。我的链接出现异常消息时出错。它没有上传,断点甚至没有开始。这是代码

[HttpPost]
        [Route("Api/Token/test")]
        public IHttpActionResult TestFile(HttpPostedFileBase file) {
            if (file != null)
            {

            }
            return Ok();
        }`

这是我上传文件的代码

var url = "http:/192.168.101.1:3000/api/token/test";
//File for Upload
 var targetPath = cordova.file.externalRootDirectory + "logo_radni.png";
// File name only
var filename = targetPath.split("/").pop();
var options = {
   fileKey: "file",
    fileName: filename,
    chunkedMode: false,
    mimeType: "image/jpg",
   params : {'directory':'upload', 'fileName':filename} 
};

$cordovaFileTransfer.upload(url, targetPath,options).then(function (result) {
console.log("SUCCESS: " + JSON.stringify(result.response));
                     }, function (err) {
                         console.log("ERROR: " + JSON.stringify(err));
                     }, function (progress) {
                         // PROGRESS HANDLING GOES HERE
                     });

这是控制台的输出 {"code":3,"source":"file:///storage/emulated/0/logo_radni.png","target":"http:/192.168.101.1:3000/api/token/test","http_status":null,"body":null,"exception":"http:/192.168.101.1:3000/api/token/test"} (21:47:56:267)

这是我的config.xml

 <access origin="*"/>
    <allow-intent href="http://*/*"/>
    <allow-intent href="https://*/*"/>
    <allow-intent href="tel:*"/>
    <allow-intent href="sms:*"/>
    <allow-intent href="mailto:*"/>
    <allow-intent href="geo:*"/>
    <allow-navigation href="http://*/*" />
    <allow-navigation href="https://*/*" />

1 个答案:

答案 0 :(得分:1)

我相信你错过了<div class="panel-body"> <div id="listingTable"> </div> <ul class="pager"> <li><a href="javascript:prevPage()" id="btn_prev">قبلی</a></li> <li><a href="javascript:nextPage()" id="btn_next">بعدی</a></li> </ul> </div> <span id="page"></span>中的斜线,它应该是http:/192.168.101.1:3000