2013-10-22 133 views
0

压缩照片我使用这个代码从Android相机的图像上传到服务器:上传之前Android摄像头拍摄到服务器

 miFoto = params[0]; 
     try { 
      HttpClient httpclient = new DefaultHttpClient(); 
      httpclient.getParams().setParameter(CoreProtocolPNames.PROTOCOL_VERSION, HttpVersion.HTTP_1_1); 
      HttpPost httppost = new HttpPost("http://www.myserver.com/upload.php"); 
      File file = new File(miFoto); 
      MultipartEntity mpEntity = new MultipartEntity(); 
      ContentBody foto = new FileBody(file, "image/jpeg"); 
      mpEntity.addPart("fotoUp", foto); 
      httppost.setEntity(mpEntity); 
      httpclient.execute(httppost); 
      httpclient.getConnectionManager().shutdown(); 
     } catch (Exception e) { 
      e.printStackTrace(); 
     } 
     return null; 

的问题是,文件尺寸太大。我已经尝试了一些方法来在上传之前压缩图像,但由于我是Android的初学者,所以对我来说这是不可能的。

谢谢。

回答

相关问题