Search code examples
javafile-uploaduploadhttpclientpostfile

POST file as binary body using CloseableHttpClient Java


I post a file using form-data but file is uploading corrupted. I need to post it as binary. How can I do it in Java using HttpClient?

"Content-Type": "application/octet-stream"


Solution

  • We can set it like below:

    post.setEntity(new FileEntity(file));