2014-01-08 65 views
2

我從Android端上傳文件(圖像,視頻和音頻)到PHP服務器。它適用於小文件。但是,對於大文件,它會給出意想不到的結果,比如文件上傳,但在android端,它會產生超時異常。 所以請幫助我,我如何解決文件上傳的所有場景。我如何使用HttpMultipart實體以及如何針對不同大小的文件設置相對超時。 我的代碼是:Android文件上傳使用loopj HttpClient

File myFile = new File(filePath); 
RequestParams params = new RequestParams(); 
try { 
    params.put("uploaded_file", myFile); 
} catch (FileNotFoundException e) { 
} 

URL=getResources().getString(com.newing.R.string.server_adderess)+URL+fileType+"&lessonID="+LessonID; 
client.post(URL, params, new AsyncHttpResponseHandler() { 
    @Override 
    public void onSuccess(String response) { 
     Log.w("async", "success!!!!"); 
     UtilityFunctions.showNotification(getApplicationContext(), 
      "File uploading completed."); 
     stopSelf(); 
    } 

    @Override 
    public void onFailure(Throwable error) { 
     Log.w("async", "failure!!!!"); 
     UtilityFunctions.showNotification(getApplicationContext(), 
      "File couldn't upload. Please try later."); 
     stopSelf(); 
    } 
}); 
+0

你可以檢查你的s上傳max_size限制erver?超時值? –

回答

0

,你可以嘗試使用Ion是用於異步網絡和一個偉大的圖書館圖像加載https://github.com/koush/ion

一個簡單的例子上傳文件

Ion.with(getContext(), "https://koush.clockworkmod.com/test/echo") .uploadProgressBar(uploadProgressBar) .setMultipartFile("filename.zip", new File("/sdcard/filename.zip")) .asJsonObject() .setCallback(...)

檢查項目網站更多的例子和維基

+0

問題如何使用loopj解決。不要建議新的插件。 –

相關問題