Java – Android: Image upload to network service loses EXIF data

Android: Image upload to network service loses EXIF data… here is a solution to the problem.

Android: Image upload to network service loses EXIF data

Please help,

I currently upload an image to my web service with EXIF data attached to the upload. When it reaches the server, it subtracts its EXIF data.

  Bitmap bmp = BitmapFactory.decodeFile(fullFileName);
                  if (bmp == null) {
                    oh sugar, not cool
                     continue;
                }
                  ByteArrayOutputStream stream = new ByteArrayOutputStream();
                  bmp.compress(Bitmap.CompressFormat.JPEG, 60, stream);
                  byte[] byteArray = stream.toByteArray();

DefaultHttpClient client = new DefaultHttpClient();
                HttpPost post = new HttpPost("webserviceurl");
                ByteArrayEntity test = new ByteArrayEntity(byteArray){...}

post.setEntity(test);   

Before I upload the image, it is stored to the device’s SD card and then decoded using the BitmapFactory class.

I was thinking it was lost during image compression, does anyone have a solution or idea?

Thanks

Cave 111

Solution

EXIF data is stripped during encoding. However, ExifInterface will allow you to set EXIF data on compressed files. Unfortunately, you need to compress the image, write it to a file, then set EXIF on the file, and finally upload it.

Related Problems and Solutions