I have a webservice running and ready to consume images produced by my Android tablet camera (Samsumg Galaxy TAB 10.1).
It works perfectly when consuming images taken at 1024x768 resolution (0.8M). However, when using the tablet's highest resolution (2048x1536, or 3.2M), the image saved simply does not work. It saves a broken image file with 0kb size.
This is the code related to the image-saving in the webservice:
public static void saveFile(final InputStream file, final String filePath) throws IOException {
OutputStream out = new FileOutputStream(new File(filePath.trim()));
int read = 0;
byte[] bytes = new byte[2048];
while ((read = file.read(bytes)) != -1) {
out.write(bytes, 0, read);
}
file.close();
out.flush();
out.close();
}
I've already tried increasing the byte array size, but it didn't help.
The file
variable is produced like this:
final InputStream image = data.getImage().getDataHandler().getInputStream();
Where data
is a object consumed via a multipart request made by the webservice to Android, like this.
Any ideas?