无法使用Cordova FileTransfer插件将文件从android上载到asp.net服务器

无法使用Cordova FileTransfer插件将文件从android上载到asp.net服务器,asp.net,cordova,file-upload,cordova-plugins,jquery-file-upload,Asp.net,Cordova,File Upload,Cordova Plugins,Jquery File Upload,我有一个简单的移动应用程序创建使用科尔多瓦文件传输插件。下面是上传代码 function uploadPhoto(fileURI) { var options = new FileUploadOptions(); options.fileKey = fileURI.substr(fileURI.lastIndexOf('/') + 1); options.fileName = fileURI.substr(fileURI.l

我有一个简单的移动应用程序创建使用科尔多瓦文件传输插件。下面是上传代码

function uploadPhoto(fileURI) {
            var options = new FileUploadOptions();
            options.fileKey = fileURI.substr(fileURI.lastIndexOf('/') + 1);
            options.fileName = fileURI.substr(fileURI.lastIndexOf('/') + 1);

            if (cordova.platformId == "android") {
                options.fileName += ".jpg" 
            }

            options.mimeType = "image/jpeg";
            //options.contentType = 'multipart/form-data';
            options.params = {}; // if we need to send parameters to the server request 

            options.headers = {
                Connection: "Close"
            };
            //options.httpMethod = 'POST';
            //options.chunkedMode = false;

            var ft = new FileTransfer();

            rst.innerHTML = "Upload in progress...";
            ft.upload(
                fileURI,
                encodeURI("http://localhost:55013/virtualroomservice.asmx/SaveImage"),
                onFileUploadSuccess,
                onFileTransferFail,
                options, true);

            function onFileUploadSuccess (result) {
               // rst.innerHTML = "Upload successful";
                console.log("FileTransfer.upload");
                console.log("Code = " + result.responseCode);
                console.log("Response = " + result.response);
                console.log("Sent = " + result.bytesSent);
                console.log("Link to uploaded file: https://www.kinrep.com/foster/ws/contentlibrary" + result.response);
                var response = result.response;
                var destination = "https://www.kinrep.com/foster/WS/ContentLibrary" + response.substr(response.lastIndexOf('=') + 1);
                if(this.id == 'uploadcheque') {
                    document.getElementById("hdnchequeimgpath").value = destination;

                } else if(this.id == 'uploaddoorlock') {

                    document.getElementById("hdndoorlockedimgpath").value = destination;
                } else {

                    document.getElementById("hdnothersimgpath").value = destination;
                }
                rst.innerHTML = "File uploaded to: " +
                                                              destination + 
                                                              "</br><button class=\"button\" onclick=\"window.open('" + destination + "', '_blank', 'location=yes')\">Open Location</button>";
                //document.getElementById("downloadedImage").style.display="none";
            }

            function onFileTransferFail (error) {
                rst.innerHTML = "File Transfer failed: " + error.code;
                console.log("FileTransfer Error:");
                console.log("Code: " + error.code);
                console.log("Source: " + error.source);
                console.log("Target: " + error.target);
            }
}
调用调用时,调用将进入SaveImage webmethod内部,但HttpContext.Current.Request.Files.Count为0。当我指向filedropper.com(如示例代码中所示)时,同样的调用工作正常(我可以在filedrop.com上看到上传的图像),但当指向我的windows web服务时,该调用不起作用。我看到过其他各种帖子,但我不知道哪里出了问题。在客户端控制台中,它不写入发送的字节数,这意味着客户端没有问题,而服务器端似乎有问题。有人能提出问题所在吗

下面是调试输出

更新-06112016-5:35PMIS 仍然不明所以也发了进来

更新-06112016-9-54PMIS


在经历了一场噩梦之后,我无法解决这个问题,我决定在iis上托管一个php作为替代方案。Cordova文件传输插件似乎与php服务器页面配合良好,因为显然,快速CGI模式下的IIS 7.5在分块多部分表单数据方面存在缺陷:

Cordova的FileTransfer插件将分块模式默认为true:

chunkedMode:是否以分块流模式上载数据。默认为true。(布尔值)

在我的例子中,这正是问题所在,将options.chunkedMode设置为true立即解决了问题

请注意,您将无法再使用onprogress属性

onprogress:每当传输新数据块时,使用ProgressEvent调用。(功能)


显然,快速CGI模式下的IIS 7.5在分块多部分表单数据方面存在缺陷:

Cordova的FileTransfer插件将分块模式默认为true:

chunkedMode:是否以分块流模式上载数据。默认为true。(布尔值)

在我的例子中,这正是问题所在,将options.chunkedMode设置为true立即解决了问题

请注意,您将无法再使用onprogress属性

onprogress:每当传输新数据块时,使用ProgressEvent调用。(功能)


不太确定这是否是防火墙问题,但刚刚确认windows防火墙已关闭,localhost正在运行尝试使用ip而不是主机名(localhost)@Gandhi,该问题与127.0.0.1相同。我认为问题在于请求头不能很好地满足2个worldsok之间的要求。尝试在options.headers={'Content-Type':'image/jpg'}中添加此选项,也可以在header选项中添加,并选中我在代码中注意到的另一件事是options.headers={Connection:“Close”};理想情况下应该是options.headers={'Connection':'Close'};不太确定这是否是防火墙问题,但刚刚确认windows防火墙已关闭,localhost正在运行尝试使用ip而不是主机名(localhost)@Gandhi,该问题与127.0.0.1相同。我认为问题在于请求头不能很好地满足2个worldsok之间的要求。尝试在options.headers={'Content-Type':'image/jpg'}中添加此选项,也可以在header选项中添加,并选中我在代码中注意到的另一件事是options.headers={Connection:“Close”};理想情况下应该是options.headers={'Connection':'Close'};然而,为了尝试这种设置,有一段时间我把它放在了一边。感谢通过'尚未尝试与此设置,有一段时间我离开了这一边。谢谢通过'
[WebMethod]
[ScriptMethod]
public string SaveImage()
{
    try
    {
        HttpPostedFile file = HttpContext.Current.Request.Files[0];
        if (file == null)
            return "0";

        string targetFilePath = Server.MapPath(@"WS\ContentLibrary") + file.FileName;
        file.SaveAs(targetFilePath);
    }
    catch (Exception ex)
    {
        string s = ex.Message;
        return s;
    }

    return "1";

}