I'm trying to upload a file to a remote API using jersey-client 1.18, but I've been unable to figure out how. Essentially, what I want to do is equivalent to the following command:
curl -sv "http://localhost:4567/api/image" -X POST -F "file=@test2.png" -F "description=a%20b%20dce"
But I can't discern any way to upload a file as multipart/form-data using jersey-client 1.x.
So far I've tried (paths and URLs modified to protect the guilty):
FileInputStream fileInputStream = new FileInputStream(new File("test2.png"));
Form form = new Form();
form.add("description", "a b dce");
form.add("file", IOUtils.toString(fileInputStream, "UTF-8"));
client.resource("http://localhost:4567/api/image")
.header("content-type", MediaType.MULTIPART_FORM_DATA)
.post(ClientResponse.class, form);
But I've only received 400s in response.
Unfortunately, switching to a different version is not an option, due to circumstances outside of my control. Any help would be appreciated!
I think this has already been answered. You should be using FormDataMultiPart