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);
}
Aggregations