2013-02-18 81 views

回答

0

FileTransfer是一個對象,允許您將文件上載到服務器或從服務器下載文件,它包含在Apache Cordova API Reference中。在我看來,使用FileTransfer對象是將文件上傳到遠程服務器的正確方法。

如果選中了Apache科爾多瓦內部的文件傳輸類的實現JAR,你會看到上傳方法的簽名是:

/** 
    * Uploads the specified file to the server URL provided using an HTTP multipart request. 
    * @param source  Full path of the file on the file system 
    * @param target  URL of the server to receive the file 
    * @param args   JSON Array of args 
    * @param callbackContext callback id for optional progress reports 
    * 
    * args[2] fileKey  Name of file request parameter 
    * args[3] fileName  File name to be used on server 
    * args[4] mimeType  Describes file content type 
    * args[5] params  key:value pairs of user-defined parameters 
    * @return FileUploadResult containing result of upload request 
    */ 
    private void upload(final String source, final String target, JSONArray args, CallbackContext callbackContext) throws JSONException { 

這意味着該方法期望接受,因爲它是第一個參數,一個源字符串(表示文件系統上文件的完整路徑),而不是一個字符串數組。

因此,如果您選擇繼續使用FileTransfer選項,可能多個FileTransfer上載調用是不可避免的。

0

在您喜歡的技術創建一個Web服務發送給服務器,允許寫入訪問在服務器上,然後爲每個圖像文件都有PhoneGap應用程序將圖像字節發送到服務器,以及元數據(如文件名和所有者)。

+0

我想我應該使用FileTransfer?但我怎樣才能發送幾個圖像文件。我的意思是我把所有這些文件放在一個表中? – 2013-02-18 16:21:08