2012-10-15 2 views
1

나는 안드로이드 phonegap에서 프로젝트를하고 있습니다. 여기 이미지 및 비디오를 원격 서버에 업로드하고 싶습니다. 다음 링크를 사용했습니다. http://zacvineyard.com/blog/2011/03/upload-a-file-to-a-remote-server-with-phonegapphonegap을 사용하여 원격 서버에 이미지 또는 비디오 업로드

options.chunkedMode = false, android : debuggable = "true"및 과 같은 일부 옵션도 변경됩니다. 하지만 여전히 오류 코드 3을 보여줍니다. cordova-2.0.0.js 버전을 사용하고 있습니다. 누구든지 몇 가지 대답을 제안 할 수 있습니까?

내 JS 코드는

** 

<script type="text/javascript" charset="utf-8"> 

      // Wait for PhoneGap to load 
    document.addEventListener("deviceready", onDeviceReady, false); 

      // PhoneGap is ready 
    function onDeviceReady() { 
     // Do cool things here... 
      } 

    function getImage() { 

       // Retrieve image file location from specified source 
       navigator.camera.getPicture(uploadPhoto, function(message) { 
       alert('get picture failed'); 
       }, 
       {quality: 50, 
       destinationType: navigator.camera.DestinationType.FILE_URI, 
       sourceType: navigator.camera.PictureSourceType.PHOTOLIBRARY 
       } 
       ); 
    } 

    function uploadPhoto(imageURI) { 

       var options = new FileUploadOptions(); 
       options.fileKey="file"; 
       options.fileName=imageURI.substr(imageURI.lastIndexOf('/')+1); 
       options.mimeType="image/jpeg"; 

       var params = new Object(); 
       params.value1 = "test"; 
       params.value2 = "param"; 

       options.params = params; 
       options.chunkedMode = false; 

       var ft = new FileTransfer(); 
       ft.upload(imageURI, "url of ther server/upload.php", win, fail, options, true); 
       console.log("H"); 
    } 

    function win(r) { 
       console.log("HIIIIIiiii"); 
       console.log("Code = " + r.responseCode); 
       console.log("Response = " + r.response); 
       console.log("Sent = " + r.bytesSent); 
       alert(r.response); 
    } 

    function fail(error) { 
       alert("There is something"); 
       alert("An error has occurred: Code = " + error.code); 
    } 

    </script> 

**

하고 내 PHP 코드는

<?php 

print_r($_FILES); 
$new_image_name = "namethisimage.jpg"; 
move_uploaded_file($_FILES["file"]["tmp_name"], "upload/".$new_image_name); 

?> 

감사합니다.

+0

업로드 중 일부 코드가 표시됩니다. –

+0

@SimonMacDonald 코드가 추가되었습니다. – Balu

+0

카메라 이미지를 올바르게 캡처합니까? –

답변

1

허용 된 사이트 목록에 해당 URL을 추가 했습니까?

<access origin="www.myurl.com" subdomains="true" /> 

또는

<access origin="*" /> 

모든 URL을 허용합니다 config.xml에 당신이 뭔가를해야합니까.

오류 코드 3은 FileTransferError.CONNECTION_ERR입니다.

+0

config.xml에 을 추가했습니다. – Balu

+0

을 제거하십시오. 아마 그 * before? –

+0

Ian Devlin 전 (*)을 제거하여 시도했습니다. 여전히 같은 오류. – Balu

관련 문제