I\'m using java-http-client library and Apache Transport with it on client side and Rails on server side. From time to time a get error like this:
11-24 17:3
I have an similar error because I used CountingInputStreamEntity that is a non-repeteable http client. The solution was to use BufferedHttpEntity which converts the non-repeteable to repeteable httpclient.
ParcelFileDescriptor fileDescriptor = this.getContentResolver().openFileDescriptor(uri, "r");
InputStream in = this.getContentResolver().openInputStream(uri);
CountingInputStreamEntity entity = new CountingInputStreamEntity(in, fileDescriptor.getStatSize());
entity.setUploadListener(this);
entity.setContentType("binary/octet-stream");
entity.setChunked(true);
BufferedHttpEntity myEntity = null;
try {
myEntity = new BufferedHttpEntity(entity);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
put.setEntity(myEntity);
I solved it as folllows:
MultipartEntityBuilder entityBuilder = MultipartEntityBuilder.create();
entityBuilder.setMode(HttpMultipartMode.BROWSER_COMPATIBLE);
ContentType contentType = ContentType.create("image/jpeg", Consts.ISO_8859_1);
entityBuilder.addBinaryBody(PARAM_ATTACHMENT, new File(filepath), contentType, StringUtils.getFileName(filepath));