我正在尝试找出一种使用 Icenium+Cordova (mobile) 和 ASP.NET 将图像从手机上传到远程服务器的方法。
我确实尝试在提供远程 Web 服务地址时使用FileTransfer()命令,但没有成功。我正在使用 Icenium 模拟器和 Visual Studio 在本地测试代码。
我需要的是移动(Javascript)和服务器(.NET)端的代码示例,以支持该图像上传通信。谢谢。
我目前使用的代码:
function uploadPhoto(imageURI) {
var options = new FileUploadOptions();
options.fileKey="image_file"; // recFile
var imagefilename = Number(new Date())+".png";
options.fileName=imagefilename;
options.mimeType= "text/plain";
options.chunkedMode = false;
params = {
val1: "some value",
val2: "some other value"
};
options.params = params;
var ft = new FileTransfer();
ft.upload(imageURI,"http://127.0.0.1:1691/ImageWebService.asmx/SaveImage", success, fail, options);
}
在服务器端:
[WebMethod]
[ScriptMethod]
public string SaveImage()
{
try
{
HttpPostedFile file = HttpContext.Current.Request.Files[0];
if (file == null)
return "0";
HttpPostedFile file =
HttpContext.Current.Request.Files[0];
string targetFilePath = "c:\\" + file.FileName;
file.SaveAs(targetFilePath);
}
catch (Exception ex)
{
}
return "1";
}
我也有:
<access origin="*" />
在科尔多瓦的 config.xml 中。
注意:我使用“Advanced Rest Client”使用标准文件上传控件测试了用于图像上传的 web 服务,它返回 200 OK。
除此之外,我被卡住了,可以找到一种方法将图像成功上传到远程服务器。我愿意使用其他方法,但我认为如果我想要最好的可比性,使用本机 Cordova FileTransfer() 是更安全的方法。