I\'m trying to upload a file and other form data using multipart/form-data client with Jersey. I\'m uploading to a REST web service also using Jersey. Here is the server c
Or just write a new file and upload it:
Writer output = null;
File file = null;
try {
String text = "Rajesh Kumar";
file = new File("write.txt");
output = new BufferedWriter(new FileWriter(file));
output.write(text);
output.close();
} catch (IOException e) {
System.out.println("IOException e");
e.printStackTrace();
}
InputStream is = null;
try {
is = new FileInputStream(file);
} catch (FileNotFoundException e) {
System.out.println("FileNotFoundException e");
e.printStackTrace();
} catch (IOException e) {
System.out.println("IOException e");
e.printStackTrace();
}
FormDataMultiPart part = new FormDataMultiPart().field("file", is, MediaType.TEXT_PLAIN_TYPE);
res = service.path("rest").path("tenant").path(tenant1.getTenantId()).path("file").type(MediaType.MULTIPART_FORM_DATA_TYPE).post(ClientResponse.class, part);