Multiple images can be uploaded for a product by a single multipart form data POST request. Binary file data and additional (product) data are multipart MIME formatted.
First, you have to specify a product identifier to identify the product entity with which the images should be associated. There are three types of identifiers:
- Id: The SmartStore.NET internal, numeric product record identifier.
- Sku: The stock keeping unit of the product.
- Gtin: A global trade item number like UPC (in North America), EAN (in Europe), JAN (in Japan) and ISBN (for books).
Use one of these types and a proper value to identify the product. In the example,
Id is used with a value of 1.
It doesn't matter if one of the uploaded images already exists. The Web API automatically ensures that a product has no duplicate images by comparing both binary data streams.
It's also possible to update/replace an existing image. To do so simply add the picture identifier as
PictureId attribute in the content disposition header. The example updates the picture entity with the Id 6166.
The response is always a JSON formatted composite model with the following properties:
- Name: The name attribute of the content-disposition multipart header.
- Filename: The filename attribute of the content-disposition multipart header.
- MediaType: The media (mime) type of the content-type multipart header.
- Exists: If the uploaded image already exists, it is ignored.
- Inserted: Indicates whether the uploaded image has been inserted.
- ImageUrl: The Url of the default size image.
- ThumbImageUrl: The Url of the thumbnail image.
- FullSizeImageUrl: The Url of the full size image.
- ContentDisposition: Raw custom parameters of the content-disposition multipart header.
- PictureId: The picture identifier.
- Picture: The picture entity. Can be blank.
Image uploading can be a resource-intensive process. We recommend the use of the async and await syntax (.NET framework 4.5), a continuation task (.NET framework 4.0) or any other parallel asynchronous mechanism targeting payload efficiency.