Search in sources :

Example 1 with StreamDataBodyPart

use of com.sun.jersey.multipart.file.StreamDataBodyPart in project pwinty-java-sdk by OddPrints.

the class Pwinty method addPhotoToOrder.

/**
 * Either the File or URL must be supplied
 */
private Photo addPhotoToOrder(int orderId, InputStream photoData, File photo, URL photoUrl, Photo.Type type, int copies, Sizing sizing) {
    @SuppressWarnings("resource") FormDataMultiPart form = new FormDataMultiPart().field("type", type.toString()).field("sizing", sizing.toString()).field("copies", "" + copies);
    if (photoData != null) {
        form.bodyPart(new StreamDataBodyPart("file", photoData));
    } else if (photo != null) {
        form.bodyPart(new FileDataBodyPart("file", photo, MediaType.APPLICATION_OCTET_STREAM_TYPE));
    } else {
        form = form.field("url", photoUrl.toExternalForm());
    }
    ClientResponse response = webResource.path("Orders/" + orderId + "/Photos").type(MediaType.MULTIPART_FORM_DATA_TYPE).header("X-Pwinty-MerchantId", merchantId).header("X-Pwinty-REST-API-Key", apiKey).post(ClientResponse.class, form);
    throwIfBad(response);
    return createReponse(response, Photo.class);
}
Also used : StreamDataBodyPart(com.sun.jersey.multipart.file.StreamDataBodyPart) ClientResponse(com.sun.jersey.api.client.ClientResponse) FormDataMultiPart(com.sun.jersey.multipart.FormDataMultiPart) FileDataBodyPart(com.sun.jersey.multipart.file.FileDataBodyPart)

Aggregations

ClientResponse (com.sun.jersey.api.client.ClientResponse)1 FormDataMultiPart (com.sun.jersey.multipart.FormDataMultiPart)1 FileDataBodyPart (com.sun.jersey.multipart.file.FileDataBodyPart)1 StreamDataBodyPart (com.sun.jersey.multipart.file.StreamDataBodyPart)1