Uploading images via http post while preserving EXIF data in Android
<p>I am brand new to Android development, and have run into an issue with my first major app that I would very much appreciate help on. The goal of this app is to allow the user to select an image stored on the phone, and upload that image to a server via a http post method, taking the JPEG binary data as a parameter. The catch is that I need to preserve the EXIF data on this as well. I currently have pushed an image onto my emulator's sdcard, and used a basic app to confirm that it is there with the EXIF data.</p>

<p>Here is what I've got so far:</p>

<p>To provide the user with a choice of images, and as a result obtain the image Uri, I use:</p>

<p><code>startActivityForResult(new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.INTERNAL_CONTENT_URI), SELECT_IMAGE);</code></p>

<p>In my activity result code, I obtain my Uri with:</p>

<pre><code>Uri selectedImage = data.getData();
</code></pre>

<p>I use this to get a bitmap of the image and display it to the user as a preview.</p>

<p>Here is where I get stuck, as I'm not sue how best to upload it. I have looked a lot at <a href="http://vikaskanani.wordpress.com/2011/01/11/android-upload-image-or-file-using-http-post-multi-part/" rel="nofollow">this example</a> in hopes of doing something similar, but he seems to be just compressing a bitmap and sending it, which would probably destroy the EXIF data I need, plus I can't even seem to get that to work.</p>

<p>This is the code I'm trying right now, which given my low experience with such things may be entirely wrong:</p>

<pre><code>Uri selectedImage = data.getData();
InputStream imageInputStream=this.getContentResolver().openInputStream(selectedImage);
String str=imageInputStream.toString();
byte[] imageBits=str.getBytes();
HttpClient client = new DefaultHttpClient();
HttpPost post = new HttpPost("where I am sending it");
ByteArrayBody toUpload = new ByteArrayBody(imageBits, "androidpic.jpg");

MultipartEntity reqEntity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE);
reqEntity.addPart("userImage", toUpload);
reqEntity.addPart("FileName", new StringBody("android pic"));
post.setEntity(reqEntity);
HttpResponse response = client.execute(post);
</code></pre>

<p>This of course does not seem to work.</p>

<p>Does anyone have experience uploading jpegs from the phone like this who could give me some pointers? Any help would be greatly appreciated.</p>
