Documentation for SmartStore.NET 2.2
Uploading Product Images
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.
POST http://localhost:1260/api/v1/Uploads/ProductImages Content-Type: multipart/form-data; boundary=----------2a7fbadf8e7d4276b4a5fdbb9f877e11 ------------2a7fbadf8e7d4276b4a5fdbb9f877e11 Content-Disposition: form-data; name="Id" 1 ------------2a7fbadf8e7d4276b4a5fdbb9f877e11 Content-Disposition: form-data; name="my-image1"; filename="iphone-white.png" Content-Type: image/png <Binary image data here (length 74290 bytes)...> ------------2a7fbadf8e7d4276b4a5fdbb9f877e11 Content-Disposition: form-data; name="my-image2"; filename="iphone-black.jpg" Content-Type: image/jpeg <Binary image data here (length 269008 bytes)...> ------------2a7fbadf8e7d4276b4a5fdbb9f877e11--
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 when processing your upload.
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.
- 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.