0

我想使用 PhoneGap 将文件发送到服务器。这是我要发送的以下函数参数文件下面的代码。问题是,如果我插入一个假 url 作为 localhost 服务器,它会显示服务器错误代码 = 2,如果我插入一个真实 url,则会显示我找不到文件代码 = 1

function gotFile(file)
{
    navigator.notification.alert(file.fullPath);

    var options = new FileUploadOptions();
        options.mimeType="image/jpg"; 
        options.fileKey="file";
        var params = {};
        params.IdPrestation = "3d660013-3028-46c3-adfa-d7141a712ed7";
        params.IdPhoto      = "3a660013-3028-46c3-adfa-d7141a712ed7";
        options.params = params;
            options.chunkedMode = true ;

      var ft = new FileTransfer();

               ft.upload(file.fullPath,encodeURI('http://Myserver.fr/Phototheque.asmx/SavePhoto'),function(r)
               {      
                   //navigator.notification.alert(r.response,function(){});
                    alert(r.response,function(){});
                    console.log("Code = " + r.responseCode);
                    console.log("Response = " + r.response);
                    console.log("Sent = " + r.bytesSent);
               },
               function(e)
               {
               //navigator.notification.alert('Serveur Erreur:' + e.code,function(){});
                    cause_erreur(e.code);
                    /*
                    alert('Serveur Erreur:' + e.code,function(){});
                    alert("upload error source " + e.source);
                    alert("upload error target " + e.target)
                    */
               },
               options
               );//ft.upload


}
4

1 回答 1

0

我不完全知道你的错误。但是,您的上传代码似乎是正常的,可能由于文件大小或网络状态而出现错误。同时,您可以在服务器中检查请求和响应是否按预期工作。

于 2013-02-22T00:11:23.463 回答