简体   繁体   中英

RESTEasy client multipart post file

I'm trying to send a file with resteasy client to an http server with some code like this:

File source = new File("test.pdf");

Client client = ClientBuilder.newClient();

MultipartFormDataOutput upload = new MultipartFormDataOutput();

upload.addFormData("source", source, MediaType.APPLICATION_OCTET_STREAM_TYPE);

Entity entity = Entity.entity(upload, MediaType.MULTIPART_FORM_DATA_TYPE)
Response response = client.target(url).request().post(entity);

What happens is that on the http server I'm not getting the usual "file" in request (with the content, the name etc..), but something like a regular POST parameter named "source" with the file content as its value. I tried it with some different web servers, so the issue have to be in the request that RESTeasy builds.

Any help?

MultipartFormDataOutput behaves the same away as a HTML form would do. It sends key/value pairs to the server.

If you want to upload a MIME message consider using MultipartOutput .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM