Search in sources :

Example 6 with FileDataBodyPart

use of com.sun.jersey.multipart.file.FileDataBodyPart 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

FormDataMultiPart (com.sun.jersey.multipart.FormDataMultiPart)6 FileDataBodyPart (com.sun.jersey.multipart.file.FileDataBodyPart)6 File (java.io.File)3 Client (com.sun.jersey.api.client.Client)2 WebResource (com.sun.jersey.api.client.WebResource)2 HTTPBasicAuthFilter (com.sun.jersey.api.client.filter.HTTPBasicAuthFilter)2 ClientResponse (com.sun.jersey.api.client.ClientResponse)1 MultiPart (com.sun.jersey.multipart.MultiPart)1 StreamDataBodyPart (com.sun.jersey.multipart.file.StreamDataBodyPart)1