Closed kzbt closed 3 years ago
The product variant draft expects the URI to a hosted image e.g. from a S3 bucket.
If you want to use the commercetools used CDN you have to use the specific upload endpoint. I just tried it and found out that the image upload endpoint seems to not be correctly working using the SDK. We will fix this with the next release.
This is a working example:
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 ByProjectKeyRequestBuilder projectRoot = CommercetoolsTestUtils.getProjectRoot();
projectRoot.products().withId(product.getId()).images().post(imageFile).withHeader(ApiHttpHeaders.CONTENT_TYPE, "image/gif").withSku(product.getMasterData().getCurrent().getMasterVariant().getSku()).executeBlocking();
Atm the withVariant is expecting a double value instead of a long. This will be fixed in soon.
A fix has been released and a test has been added to show the usage:
Does the SDK has the equivalent of https://docs.commercetools.com/api/projects/products#upload-a-product-image? I'm trying to upload an image to a variant. The
ProductVariantDraft
takes anImage
object but we first need to upload the image to get the url right? Which api from the sdk can I use to upload the image?