public final class ProductImageUploadCommand extends CommandImpl<Product>
Uploads a binary image file to a given ProductVariant
. The supported image formats are JPEG, PNG and GIF.
Example usage executing the command:
withUpdateableProduct(client(), product -> { final ByIdVariantIdentifier identifier = product.getMasterData().getStaged().getMasterVariant().getIdentifier(); File imageFile ; try{ imageFile = File.createTempFile("ct_logo_farbe",".gif"); imageFile.deleteOnExit(); byte[] fileBytes = IOUtils.toByteArray(ClassLoader.getSystemResourceAsStream("ct_logo_farbe.gif")); FileOutputStream outStream = new FileOutputStream(imageFile); outStream.write(fileBytes); outStream.close(); }catch(IOException e){ imageFile = new File("src/test/resources/ct_logo_farbe.gif"); } final ProductImageUploadCommand cmd = ProductImageUploadCommand .ofVariantId(imageFile, identifier) .withFilename("logo.gif") .withStaged(true); final Product updatedProduct = client().executeBlocking(cmd); final Image image = updatedProduct.getMasterData().getStaged().getMasterVariant().getImages().get(0); assertThat(image.getDimensions().getHeight()).isEqualTo(102); assertThat(image.getDimensions().getWidth()).isEqualTo(460); assertThat(image.getUrl()).contains("logo"); return updatedProduct; });
See the test code.
Modifier and Type | Method and Description |
---|---|
HttpRequestIntent |
httpRequestIntent()
Provides an http request intent, this does not include the execution of it.
|
protected com.fasterxml.jackson.databind.JavaType |
jacksonJavaType() |
static ProductImageUploadCommand |
ofMasterVariant(File body,
String productId) |
static ProductImageUploadCommand |
ofProductIdAndSku(File body,
String productId,
String sku) |
static ProductImageUploadCommand |
ofVariantId(File body,
ByIdVariantIdentifier variantIdentifier) |
ProductImageUploadCommand |
withContentType(String contentType)
Sets the type of the Type of the uploaded image
|
ProductImageUploadCommand |
withFilename(String newFilename) |
ProductImageUploadCommand |
withStaged(Boolean newStaged) |
deserialize
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
canDeserialize
public static ProductImageUploadCommand ofMasterVariant(File body, String productId)
public static ProductImageUploadCommand ofProductIdAndSku(File body, String productId, String sku)
public static ProductImageUploadCommand ofVariantId(File body, ByIdVariantIdentifier variantIdentifier)
public ProductImageUploadCommand withFilename(String newFilename)
public ProductImageUploadCommand withStaged(Boolean newStaged)
public ProductImageUploadCommand withContentType(String contentType)
contentType
- must be one of "image/jpeg", "image/png" or "image/gif"protected com.fasterxml.jackson.databind.JavaType jacksonJavaType()
jacksonJavaType
in class CommandImpl<Product>
public HttpRequestIntent httpRequestIntent()
SphereRequest