2011-05-06 107 views
2
class VideoUploadTask extends AsyncTask<Void, Void, String> { 
    @Override 
    protected 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); 
    } 

收到错误IllegalStateException异常:内容已在日志cat.what被消耗的问题我不是能find.Please帮我纠正这个错误。IllegalStateException异常:内容都被消耗

问题IllegalStateException:已消耗内容已解决。但通过这种编码,我无法上传视频。请给我一些建议。

回答

6

你打电话的getContent()两次:

  InputStream in = response.getEntity().getContent(); 
      BufferedReader reader = new BufferedReader(
        new InputStreamReader(
          response.getEntity().getContent(), "UTF-8")); 

使用in创建读者。

+0

thanx ..解决。 :) – Saurabh 2011-05-07 04:22:52