0

I am using this code to upload an image from the android camera to a server:

        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;

The problem is that file size is too big. I have tried some ways to compress the image before upload it, but as I am a beginner in android, it is being impossible for me.

Thank you.

David
  • 315
  • 1
  • 4
  • 8

1 Answers1

0

I guess you could resize the image to a lower resolution and rewrite the file, then upload it. The process of resizing can be seen here.

How to resize image (Bitmap) to a given size?

Community
  • 1
  • 1
Sivakumar S
  • 681
  • 5
  • 19