0
我開發一個應用程序,使用nojs作爲服務器,它的主要功能是上傳圖片,視頻和注意服務器。如何實現待處理的上傳到服務器的android
我想約需當用戶限制帶寬或沒有互聯網連接,所以我想在我的應用程序改變狀態設置爲掛起的所有文件,並等待用戶的util找回了互聯網連接的情況護理。
這裏是我的AsyncTask類代碼上傳
File file = new File(imgPath);
//Create the POST object
HttpPost post = new HttpPost(url);
MultipartEntity entity = new MyMultipartEntity(new ProgressListener()
{
@Override
public void transferred(long num)
{
//Call the onProgressUpdate method with the percent completed
publishProgress((int) ((num/(float) totalSize) * 100));
Log.d("DEBUG", num + " - " + totalSize);
}
});
//Add the file to the content's body
ContentBody cbFile = new FileBody(file, "video/mp4");
entity.addPart("source", cbFile);
//After adding everything we get the content's lenght
totalSize = entity.getContentLength();
//We add the entity to the post request
post.setEntity(entity);
//Execute post request
HttpResponse response = client.execute(post);
int statusCode = response.getStatusLine().getStatusCode();
if(statusCode == HttpStatus.SC_OK){
//If everything goes ok, we can get the response
String fullRes = EntityUtils.toString(response.getEntity());
Log.d("DEBUG", fullRes);
} else {
Log.d("DEBUG", "HTTP Fail, Response Code: " + statusCode);
}
任何想法來解決這個問題?