C# WCF OData的Phonegap文件传输上载问题
我正在尝试使用phonegap“FileTransfer”上载文件。我正在使用.NET WCF OData上传图像。 “upload”函数未调用my API,并返回以下错误消息:C# WCF OData的Phonegap文件传输上载问题,c#,wcf,file-upload,cordova,odata,C#,Wcf,File Upload,Cordova,Odata,我正在尝试使用phonegap“FileTransfer”上载文件。我正在使用.NET WCF OData上传图像。 “upload”函数未调用my API,并返回以下错误消息: {"code":null,"source":null,"http_stats":null,"body":null} 我描述的代码如下: navigator.camera.getPicture(function(imageURI){ var url = encodeURI("http://api.xyz.com/Da
{"code":null,"source":null,"http_stats":null,"body":null}
我描述的代码如下:
navigator.camera.getPicture(function(imageURI){
var url = encodeURI("http://api.xyz.com/DataService/DataService.svc/UploadImage");
var params = new Object();
params.id= parseInt(1);
var options = new FileUploadOptions();
options.fileKey = "file";
options.fileName = imageURI.substr(imageURI.lastIndexOf('/') + 1);
options.mimeType = "image/jpeg";
options.params = params;
options.chunkedMode = true;
var ft = new FileTransfer();
ft.upload(imageURI, url, function (data) { alert(JSON.stringify(data)) }, function (data) { alert(JSON.stringify(data)) }, options);
}
[WebInvoke]
public void UploadImage(int id)
{
// **what to write here???**
}
我的WCF OData代码如下:
navigator.camera.getPicture(function(imageURI){
var url = encodeURI("http://api.xyz.com/DataService/DataService.svc/UploadImage");
var params = new Object();
params.id= parseInt(1);
var options = new FileUploadOptions();
options.fileKey = "file";
options.fileName = imageURI.substr(imageURI.lastIndexOf('/') + 1);
options.mimeType = "image/jpeg";
options.params = params;
options.chunkedMode = true;
var ft = new FileTransfer();
ft.upload(imageURI, url, function (data) { alert(JSON.stringify(data)) }, function (data) { alert(JSON.stringify(data)) }, options);
}
[WebInvoke]
public void UploadImage(int id)
{
// **what to write here???**
}
我还尝试了以下代码,但是window.resolveLocalFileSystemURI函数在NPObject错误上抛出一个调用方法的错误
navigator.camera.getPicture(function (imageURI) {
var _this = this;
var encodedURL = encodeURI("http://api.xyz.com/DataService/DataService.svc/UploadImage");
try {
this.op = new FileUploadOptions();
this.op.fileKey = "file";
this.op.fileName = imageURI.substr(imageURI.lastIndexOf('/') + 1);
this.op.mimeType = "image/jpeg";
this.op.chunkedMode = false;
this.op.headers = { Connection: "close" };
this.ft = new FileTransfer();
if (window.device != undefined && device.platform == "Android") {
window.resolveLocalFileSystemURI(imageURI, function (fileEntry) {
fileEntry.file(function (fileObj) {
var fileFullPath = fileObj.fullPath;
_this.op.fileName = fileFullPath.substr(fileFullPath.lastIndexOf('/') + 1);
_this.ft.upload(fileFullPath, encodedURL, function (data) { alert("Success: " + JSON.stringify(data)); }, function (data) { alert("Failour: " + JSON.stringify(data)); }, _this.op, true);
});
});
} else {
this.ft.upload(imageURI, encodedURL, function (data) { alert("Success: " + JSON.stringify(data)); }, function (data) { alert("Failour: " + JSON.stringify(data)); }, this.op, true);
}
} catch (_error) {
alert(_error);
}
},
function (message) { },
{
quality: 50,
destinationType: navigator.camera.DestinationType.FILE_URI,
sourceType: navigator.camera.PictureSourceType.PHOTOLIBRARY
});
}
imageURI是一个navigator.camera.DestinationType.FILE\u Uri我的意思是说,您是否使用了获取实际文件路径我用上述代码尝试过,但window.resolveLocalFileSystemURI函数在NPObject错误上引发调用方法的错误