2014-10-08 65 views
0

現在,我在上傳服務器上的一些圖像時遇到了問題。我的代碼完全適用於iOS設備,但是當我嘗試在Android上進行上傳時,它只是沒有做任何事情。在文件傳輸之前,我試圖提醒ImageURI,但這並沒有發生。Phonegap Filetransfer在iOS上工作在Android上沒有任何反應

我正在使用PhoneGap Build的Phonegap版本3.4.0和Sencha Touch 2.3。在config.xml中我使用核心PhoneGap的攝像頭插件:<gap:plugin name="org.apache.cordova.camera" />.

我的文件上傳腳本是這樣的:

Ext.define('my_app.controller.Fileupload', { 
    extend: 'Ext.app.Controller', 
    requires: [ 
     'Ext.MessageBox' 
    ], 
    config: { 
     refs: { 
      fileupload: '#fileupload', 
      getLibraryImage: 'button[action=getLibraryImage]', 
      getCameraImage: 'button[action=getCameraImage]' 
     }, 
     control: { 
      getLibraryImage: { 
       tap: 'getLibraryImage' 
      }, 
      getCameraImage: { 
       tap: 'getCameraImage' 
      } 
     } 
    }, 
    getLibraryImage: function() { 

     navigator.camera.getPicture(this.fileupload, onFail, { 
      destinationType: Camera.DestinationType.FILE_URI, 
      sourceType: Camera.PictureSourceType.PHOTOLIBRARY, 
      allowEdit: true, 
      targetWidth: 800, 
      targetHeight: 800 
     }); 

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

    }, 
    getCameraImage: function() { 

     navigator.camera.getPicture(this.fileupload, onFail, { 
      destinationType: Camera.DestinationType.FILE_URI, 
      sourceType: Camera.PictureSourceType.CAMERA, 
      quality: 100, 
      allowEdit: true, 
      targetWidth: 800, 
      targetHeight: 800 
     }); 

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

    }, 
    fileupload: function(imageURI) { 

    alert(imageURI); 

     Ext.Viewport.setMasked({ 
      xtype: 'loadmask', 
      message: Loc.t('LOADMASK.FILEUPLOAD'), 
      styleHtmlContent: true, 
      indicator: true 
     }); 

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

// if (Ext.os.is('Android')) { 
//  options.chunkedMode = true; 
// } 

     var user = JSON.parse(localStorage.getItem('user')); 

     var user_id = user.id; 
     var username = user.username; 

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

     var ft = new FileTransfer(); 
     ft.upload(imageURI, encodeURI("my_upload_uri"), win, fail, options); 

     function win(response) { 

      if (Ext.JSON.decode(response.response).error) { 

       Ext.Viewport.setMasked(false); 
       Ext.Msg.alert('my_app', Ext.JSON.decode(response.response).error); 

      } else { 


       my_app.app.getController('Basic').ProfileImages(); 
       Ext.Msg.alert('my_app', Ext.JSON.decode(response.response).success); 


      } 


     } 

     function fail(error) { 

      Ext.Viewport.setMasked(false); 

      alert("An error has occurred: Code = " + error.code); 
     } 

    } 
}); 

如果任何人都可以看到這個問題,我會很感激的幫助!提前致謝。

回答

0

我的問題通過升級到PhoneGap版本3.6.3解決。

相關問題