IllegalStateException: Content has been consumed
class VideoUploadTask extends AsyncTask<Void, Void, String> {
@Override
p开发者_开发问答rotected String doInBackground(Void... unsued) {
try {
Log.i("VideoUploadTask", "enters");
HttpClient httpClient = new DefaultHttpClient();
HttpContext localContext = new BasicHttpContext();
HttpPost httpPost = new HttpPost(
"http://192.168.5.10/ijoomer_development/index.php?option=com_ijoomer&plg_name=jomsocial&pview=album&ptask=upload_video&session_id="+ConstantData.session_id +"");
MultipartEntity entity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE);
ByteArrayOutputStream bos = new ByteArrayOutputStream();
// bitmap.compress(CompressFormat.JPEG, 100, bos);
byte[] data = bos.toByteArray();
Log.i("categoryId in vedio upload2", ""+ConstantData.categoryId);
entity.addPart("categoryId", new StringBody(ConstantData.categoryId.toString()));
entity.addPart("video", new ByteArrayBody(data, "myvideo.mp4"));
/*
* entity.addPart("photoCaption", new
* StringBody(caption.getText() .toString()));
*/
httpPost.setEntity(entity);
HttpResponse response = httpClient.execute(httpPost,localContext);
InputStream in = response.getEntity().getContent();
BufferedReader reader = new BufferedReader(
new InputStreamReader(
response.getEntity().getContent(), "UTF-8"));
String sResponse = reader.readLine();
String strResponse = convertStreamToString(in);
System.out.println(strResponse);
if (dialog.isShowing())
dialog.dismiss();
return strResponse;
} catch (Exception e) {
if (dialog.isShowing())
dialog.dismiss();
// Toast.makeText(getApplicationContext(),"Exception Image",Toast.LENGTH_LONG).show();
Log.e(e.getClass().getName(), e.getMessage(), e);
return null;
}
// (null);
}
getting error IllegalStateException: Content has been consumed in log cat.what is the problem i m not able to find.Please help me to correct this error.
Problem of IllegalStateException: Content has been consumed has been solved. But by this coding i am not able to upload the video. Please give me some suggestion.
You're calling getContent() twice:
InputStream in = response.getEntity().getContent();
BufferedReader reader = new BufferedReader(
new InputStreamReader(
response.getEntity().getContent(), "UTF-8"));
Use in
to create the reader.
精彩评论