0
我正在使用Cordova編寫的使用Cordova編寫的後端服務器的跨平臺移動應用程序 我想使用REST API 從應用程序上傳文件到服務器。我只是想檢查方法是否會使用斷點來調用。作爲異常消息,我的鏈接出現錯誤。它不會上傳,並且中斷點甚至不會啓動。下面是代碼使用ngCordova進行文件上傳的Excetipn
[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://*/*" />
您在代碼中缺少一個斜線:'http:/192.168.101.1:3000' =>'http://192.168.101.1:3000' – e666