2016-12-05 120 views
0

我有一個非常簡單的應用程序,可以從相機和庫上傳圖片。我設法按預期工作,出於某種原因,我停止了工作。我甚至從一個提交下載了文件,我確定它正在工作,它現在不在了。使用phonegap上傳文件到服務器的問題cordova

該應用程序讓你拍照的,從其中選擇一個畫廊,它則增加了一個小的縮略圖(這工作)的圖像拍攝/選擇讓你提交表單。選擇文件後,上傳就會立即生效,並且表單提交將包含這些文件的電子郵件作爲附件發送(在服務器上完成)。

上傳功能總是返回「發生了一個錯誤:代碼= 1」

編輯:我通過我的設備連接到PhoneGap的Windows服務器測試應用。

EDIT2:顯然這個問題是PhoneGap的模擬器,試圖在真實的apk安裝和它的工作。

CODE:

// Wait for device API libraries to load 
    // 
    document.addEventListener("deviceready", onDeviceReady, false); 
    // device APIs are available 
    // 
    function onDeviceReady() { 
     // Now safe to use device APIs 
     //alert("Device Ready"); 
     /*button that opens camera and takes picture*/ 
     $("#add_photo").click(function(){ 
      navigator.camera.getPicture(onSuccess, onFail, { quality: 50, 
      sourceType: Camera.PictureSourceType.CAMERA, 
      destinationType: Camera.DestinationType.FILE_URI }); 
     }); 

     /*on success show thumbnail and try to upload*/ 
     function onSuccess(imageURI) { 
      $("#preview").append("<img src='"+imageURI+"'/>"); 
      fileUpload(imageURI, "image/jpeg"); 
     } 

     function onFail(message) { 
      alert('Failed because: ' + message); 
     } 

     function fileUpload(imageURI, mimeType){ 
     var win = function (r) { 
      console.log("Code = " + r.responseCode); 
      console.log("Response = " + r.response); 
      console.log("Sent = " + r.bytesSent); 
      $('#form_submit').prop('disabled', false); 
      $('#form_submit').prop('value', 'ENVIAR'); 
      //alert("done"); 
      //alert(r.response); 
     } 
     var fail = function (error) { 
      alert("An error has occurred: Code = " + error.code); 
      console.log("upload error source " + error.source); 
      console.log("upload error target " + error.target); 
     } 
     var options = new FileUploadOptions(); 
     options.fileKey = "file"; 
     options.fileName = imageURI.substr(imageURI.lastIndexOf('/') + 1); 
     options.mimeType = mimeType; 
     var params = {}; 
     i++; 
     sent_files[i] = session_id+"-"+i+"."+imageURI.split('.').pop(); 
     params.session_id = sent_files[i]; 
     $('[name=send]').val(sent_files.join()); 
     options.params = params; 
     $('#form_submit').prop('disabled', true); 
     $('#form_submit').prop('value', 'CARGANDO'); 
     var ft = new FileTransfer(); 
     ft.upload(imageURI, encodeURI("http://myServer/folder"), win, fail, options); 
     }; 
    } 
+0

試圖在真實設備安裝目錄,而不是使用PhoneGap的仿真器和它的工作如預期。 –

回答

0

我試圖在真實設備安裝目錄,而不是使用PhoneGap的Windows服務器仿真器和它的工作如預期。

愚蠢的我。

相關問題