Skip to main content

Uploading files

At the moment the only way to upload a file is to use a MultipartBody, Attachment or File:

WebClient client = WebClient.create("http://books");
client.type("multipart/form-data");
ContentDisposition cd = new ContentDisposition(
   "attachment;filename=image.jpg");
Attachment att = new Attachment("root", imageInputStream, cd);
client.post(new MultipartBody(att));

// or just post the attachment if it's a single part request only
client.post(att);

// or just use a file
client.post(getClass().getResource("image.png").getFile());

Using File provides a simpler way as the runtime can figure out how to create a ContentDisposition from a File.

Did this page help you?

If you find any issues with this page or its content – a typo, a missing step, or a technical error – please let us know!