Search in sources :

Example 1 with FileDataBodyPart

use of org.glassfish.jersey.media.multipart.file.FileDataBodyPart in project camel by apache.

the class BonitaAPIUtil method uploadFile.

public UploadFileResponse uploadFile(ProcessDefinitionResponse processDefinition, FileInput file) throws Exception {
    WebTarget resource = webTarget.path("portal/resource/process/{processName}/{processVersion}/API/formFileUpload").resolveTemplate("processName", processDefinition.getName()).resolveTemplate("processVersion", processDefinition.getVersion());
    File tempFile = File.createTempFile("tempFile", ".tmp");
    FileOutputStream fos = new FileOutputStream(tempFile);
    fos.write(file.getContent());
    fos.close();
    final FileDataBodyPart filePart = new FileDataBodyPart("file", tempFile, MediaType.APPLICATION_OCTET_STREAM_TYPE);
    final MultiPart multipart = new FormDataMultiPart().bodyPart(filePart);
    return resource.request().accept(MediaType.APPLICATION_JSON).post(entity(multipart, MediaType.MULTIPART_FORM_DATA), UploadFileResponse.class);
}
Also used : MultiPart(org.glassfish.jersey.media.multipart.MultiPart) FormDataMultiPart(org.glassfish.jersey.media.multipart.FormDataMultiPart) FileOutputStream(java.io.FileOutputStream) FormDataMultiPart(org.glassfish.jersey.media.multipart.FormDataMultiPart) WebTarget(javax.ws.rs.client.WebTarget) File(java.io.File) FileDataBodyPart(org.glassfish.jersey.media.multipart.file.FileDataBodyPart)

Aggregations

File (java.io.File)1 FileOutputStream (java.io.FileOutputStream)1 WebTarget (javax.ws.rs.client.WebTarget)1 FormDataMultiPart (org.glassfish.jersey.media.multipart.FormDataMultiPart)1 MultiPart (org.glassfish.jersey.media.multipart.MultiPart)1 FileDataBodyPart (org.glassfish.jersey.media.multipart.file.FileDataBodyPart)1