I am uploading a file through multipartEntityBuilder in java. file get uploaded but gets corrupted, as content header gets mixed with data at file.
getting error in text and image formats working fine for pdf.
HttpClient httpclient =new HttpClient();
HttpPut post = new HttpPut(uploadfileurl);
File file = new File(fileUrl);
MultipartEntityBuilder builder = MultipartEntityBuilder.create();
builder.setMode(HttpMultipartMode.BROWSER_COMPATIBLE);
builder.addBinaryBody("upfile", file, ContentType.DEFAULT_BINARY, "test.txt");
builder.addTextBody("text", message, ContentType.TEXT_PLAIN);
HttpEntity entity = builder.build();
post.setEntity(entity);
post.setHeader("enctype", "multipart/form-data");
HttpResponse httpresponse = httpclient.execute(post);
HttpEntity resEntity = httpresponse.getEntity();
Error in file :: this should be like this :
this file is for testing
but it going like this :
---------------1427465571114 Content-Disposition: form-data; name="upfile"; filename="" Content-Type: application/octet-stream
this file is for testing
---------------1427465571114--