First, I use this code to save a photo on an Android SD card:
PictureCallback jpegCallback = new PictureCallback() {
public void onPictureTaken(byte[] data, Camera camera) {
FileOutputStream outStream = null;
currentFilename = String.format("%d", System.currentTimeMillis());
outStream = new FileOutputStream("/sdcard/" + currentFilename + ".jpg");
outStream.write(data);
outStream.close();
}
};
Then I use this code to upload photos on Android devices:
public void uploadPhoto() {
try {
HttpPost post = new HttpPost("http://www.example.com/upload.php");
HttpClient client = new DefaultHttpClient();
client.getParams().setParameter(CoreProtocolPNames.PROTOCOL_VERSION, HttpVersion.HTTP_1_1);
MultipartEntity entity = new MultipartEntity( HttpMultipartMode.BROWSER_COMPATIBLE );
entity.addPart( "userfile", new FileBody(
new File( "/sdcard/", currentFilename + ".jpg" ),
"image/jpeg")
);
post.setEntity( entity );
client.execute( post );
} catch (Exception e) {
} finally {
}
}
This works on my LG Optimus V running Android 2.2.2 and Droid X with Android 2.3.4
However, a user who has an HTC Evo running 2.3.4 (the same as my Droid X) experiences that all downloaded photos are scrambled when they are saved on her phone (and when they get to the server). The image looks like an array of jagged colored lines.
Any ideas on what might be happening here and what can be done to fix the problem?
Update:
, jpg SD-, , 3,5 - 4,0 , ... .