2011-05-06 61 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

相關問題