上传代码,谁知道用httpclent上传怎么中断正在上传的文件呀代码如下



id=fi.getParentid();
id = id == null ? "0" : id;
me.addPart("parentid", new StringBody(id));
me.addPart("name",new StringBody(fileName, Charset.forName("UTF-8")));
String md5 = FileMD5.getMD5(file);
me.addPart("hash", new StringBody(md5));
// 设置流文件
me.addPart("filedata", new FileBody(file));
request.setEntity(me);
   HttpResponse httpResponse = new DefaultHttpClient().execute(request);


int res = httpResponse.getStatusLine()
.getStatusCode();
String strResult = EntityUtils
.toString(httpResponse.getEntity());


if (res == 200 && strResult != null) {
JSONObject jsonObj;
jsonObj = new JSONObject(strResult);
String str = (String) jsonObj.get("result");
if (Constant.STATE_SUCCESS.equals(str)) {
fi.setState(Constant.STATE_SUCCESS);
fi.setCdate(getDate());
dbHelper.updateFileInfo(fi);
Thread.sleep(1000);
sendMsg(1);
} else {
String errorCode =getErrorCode(strResult);
int ecode=Integer.parseInt(errorCode);
fi.setState(Constant.STATE_FAILURE);
fi.setCdate(getDate());
dbHelper.updateFileInfo(fi);
sendMsg(ecode);
}
} else {
fi.setState(Constant.STATE_FAILURE);
fi.setCdate(getDate());
dbHelper.updateFileInfo(fi);
sendMsg(500);
}

你可能感兴趣的:(android,HttpClent文件上传)