2014-09-22 5 views
0

외부 웹 사이트에 입력 (유형 - 파일) 입력란이 있으며이 입력에 이미지를 업로드해야합니다. android에서이 작업을 WebChromeClient 및 openFileChooser (ValueCallback uploadMsg, String acceptType, String capture) 함수로 수행했습니다. phonegap/cordova에서이 작업을 해결하는 방법을 모르겠습니다.Phonegap/Cordova 업로드 이미지 파일

내 코드는 다음과 같습니다 기본 코르도바 응용 프로그램

function initialize() { 
    document.addEventListener('deviceready', onDeviceReady, false); 
    var ref = null; 
} 
function onDeviceReady() { 

    ref = window.open('http://example.com', 
      '_blank', 'location=no', 'EnableViewPortScale=yes'); 
    ref.addEventListener('loadstop', LoadStop); 

} 

function LoadStop(event) { 
    if (event.url == 'http://example.com/Add') { 
     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) { 
    console.log("imageURI----: " + imageURI); 

    var options = new FileUploadOptions(); 
    options.fileKey = "file"; 
    options.fileName = "IMAG0475"; 
    options.mimeType = "image/*"; 

    var params = new Object(); 
    options.params = params; 

    var ft = new FileTransfer(); 
    ft.upload(imageURI, 
      encodeURI("http://example/Add"), win, 
      fail, options); 

} 

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

function fail(error) { 
    alert("An error has occurred: Code = " + error.code); 
    console.log("upload error source " + error.source); 
    console.log("upload error target " + error.target); 
} 
+0

이것을 확인하십시오. http://stackoverflow.com/questions/24139295/form-file-upload-phonegap/24142596#24142596 – Aravin

답변

0

예, sdcard에, 외부 파일을 안드로이드 폰에있는 모든 저장 위치에 액세스 할 수 없습니다.

는이 문제를 해결하려면, 당신 코르도바 프로젝트의 config.xml에 다음 행을 복사

<preference name="AndroidExtraFilesystems" value="files,files-external,documents,sdcard,cache,cache-external,root"/> 

의 Config.xml는 /platforms/android/res/xml/config.xml에서 찾을 수 있습니다

위의 행을 추가하고 프로젝트를 다시 빌드하기 만하면됩니다.

+0

내 문제가 해결되지 않았습니다. – dirtrider