2012-04-28 6 views
0

phonegap api에서 FileTransfer.upload를 사용하여 이미지를 업로드하려고했습니다. 오류가 발생했습니다.이 오류는 "연결 오류"이며 오류 코드는 3입니다.안드로이드 phonegap에서 서버에 이미지를 업로드하는 방법

Here is my code. 
<!DOCTYPE html> 
<html> 
<head> 
<title>Video Uploader</title> 
<meta name="viewport" content="width=device-width, initial-scale=1"> 
<link rel="stylesheet" href="master.css" type="text/css" /> 
<script type="text/javascript" charset="utf-8"src="phonegap-1.1.0.js"></script> 
<script src="Scripts/jQuery-1.6.1.min.js" type="text/javascript"></script> 
<script src="Scripts/jquery-1.4.1.js" type="text/javascript"></script> 
<script src="Scripts/jquery-1.4.1-vsdoc.js" type="text/javascript"></script> 

<script type="text/javascript" charset="utf-8"> 
function getphoto(){ 
    navigator.camera.getPicture(uploadPhoto,function(message) { 
    alert('get picture failed'); 
    },{ quality:10,destinationType:navigator.camera.DestinationType.FILE_URI,sourceType:navigator.camera.PictureSourceType.PHOTOLIBRARY }); 
    } 

    function uploadPhoto(imageURI) { 

     document.getElementById("myimg").src=imageURI; 

     var options = new FileUploadOptions(); 
     options.chunkedMode = false; 
     options.fileKey="recFile"; 
     var imagefilename = imageURI; 
     options.fileName=imagefilename; 
     options.mimeType="image/jpeg"; 


     var ft = new FileTransfer(); 
     alert(imagefilename); 


     ft.upload(imageURI, "http://xxxx.asmx", win, fail, options,true); 
    } 
    function win(r) { 

     alert("Response = " + r.response); 
     alert("Sent = " + r.bytesSent); 
    } 
    function fail(error) { 
    switch (error.code) { 
       case FileTransferError.FILE_NOT_FOUND_ERR: 
        alert("Photo file not found"); 
        break; 
       case FileTransferError.INVALID_URL_ERR: 
        alert("Bad Photo URL"); 
        break; 
       case FileTransferError.CONNECTION_ERR: 
        alert("Connection error"); 
        break; 
      } 

     alert("An error has occurred: Code = " + error.code); 
    } 
    </script> 
    </head> 
    <body > 
    <button onclick="getphoto();">get a Photo</button> 
    <button onclick="getphoto();">Upload a Photo</button> 
    <img src="" id="myimg" style="border:1px solid #0f0;height:200px;width:200px;" /> 

    </body> 
    </html> 

것을 참조하시기 바랍니다과 solution.What이

답변

0

가 다른 서버로 업로드하려고 적이 폰갭 API의 upload.php로의 개념 말해? 업로드가 성공하면 서버 설정에 문제가있을 수 있습니다. 나는이 문제가있어서 내 nginx/승객 conf를보기 시작했다.

편집 :

내가 (1메가바이트에 기본값)의 nginx에 client_max_body_size 설정을 증가시켜이 문제를 해결했다.

또한 "ft.upload"("true")의 마지막 매개 변수는 https 요청을위한 것으로,이 경우 생략해야합니다.

관련 문제