Skip to main content
Skip table of contents

Uploading images

One common way to make images available to the image server is by using the Asset Library or direct access facilities within the Customizer. For detailed information, refer to the (see Image sources | Image-file-storage).

However, there are scenarios where images need to be added dynamically or through an API. These scenarios include, but are not limited to:

  • A customer uploading a user-generated (UGC) image to be used for personalization purposes

  • A custom ETL process uploading product images based on a catalog import

While both use cases follow a similar workflow, they may require different parameters depending on the specific upload path.

Making requests

Unlike rendering requests that utilize the CDN endpoint fx.images.drivecommerce.com, upload requests should always use the API endpoint - api.images.drivecommerce.com

The general request URL form shall be in the format:

https://api.images.drivecommerce.com/api/v1/<client name>/image/upload

Upload requests shall use POST HTTP method and submit the data using a multipart HTTP request.

For example: JavaScript code uploading an UGC image from an <input> element:

JS
const formData = new FormData();

// Upload a file.
formData.append('file', file);

formData.append('min-width', '300');
formData.append('min-height', '300');

formData.append('fit', 'cover');

formData.append('fit-width', '2000');
formData.append('fit-height', '2000');

axios({
    method: 'post',
    url: '//api.images.drivecommerce.com/api/v1/image/client/upload/',
    data: formData,
    config: {
        headers: { 'Content-Type': 'multipart/form-data' },
    },
    onUploadProgress: (progressEvent) => {
        // Track upload progress in percents: (progressEvent.loaded / progressEvent.total) * 100;
    },
}).then((response) => {
    // Done, process the response.
}).catch((error) => {
    // Failed, read the error data.
    if (error && error.response && error.response.data) {
        const { data } = error.response;
    }
});

Authentication

Depending on the use case, some uploads may require authentication. To enable this functionality, please contact Drive Commerce support to obtain the API keys associated with your account.

Authentication parameters can be supplied using one of the following methods:

  • Form Parameter: Include the authentication details directly within the form data.

  • Authorization Header: Use the Authorization HTTP header to pass authentication credentials.

Form authorization

Submit the API key using apikey form parameter.

Header authorization

Submit the API key using Authorization Bearer credentials:

Authorization: Bearer <api-key>

User generated content vs permanent assets

The upload API intakes two types of image content.

User generated generated content

User-generated content (UGC) assets are designed to be uploaded by end users to add a personal touch to their custom products. Examples include printing a custom photo or etching a design. UGC assets are ephemeral by nature and are subject to deletion after a predefined period, typically soon after an order has been placed and potentially processed for manufacturing.

UGC uploads are intended to originate from public Internet contexts, such as a browser or mobile app. These upload actions do not require API authentication.

When uploading UGC, do not include the name parameter. The asset will automatically be assigned a randomly generated name, regardless of the original file or URL name.

Permanent assets

Permanent assets, such as product images, 3D models, and font files, are typically uploaded once and reused across multiple product renderings.

Unlike user-generated content, permanent assets are not deleted automatically.

To designate an asset as permanent, you must assign it a unique name using the name parameter.

It is the customer’s responsibility to ensure that asset names are unique. Uploading a new asset with an existing name will overwrite the previous asset, and this action cannot be undone

An API key is required when uploading permanent assets.

Specifying the image source

Assets—whether user-generated content (UGC) or permanent—can be uploaded using one of two methods:

  • File Upload: Use the file parameter to provide a multipart form-encoded file source.

  • Remote Copy: Use the copy-from parameter to specify an image source, either as a URL or as raw image data.

When using the copy-from parameter:

  • If the value begins with the https:// prefix, it will be treated as an image URL.

  • If no https:// prefix is present, the value will be treated as base64-encoded image data.

If the base64 data is corrupted or cannot be decoded as a valid image, the image server will return an error.

Validating input images

Uploaded images are always validated to ensure they contain valid image data. Additionally, extra constraint parameters can be used to enforce specific validation rules.

Parameter name

Description

min-width

Minimum image width. For example, when using the constraint min-width=300, an error will be generated when uploading images smaller than the specified dimension.

min-height

Minimum image height.

max-width

Maximum image width.

max-height

Maximum image height.

Cropping images

Images can be cropped during the upload process by specifying a set of parameters. All parameters must be specified at the same in order to trigger this functionality.

Parameter name

Description

crop-x

X (horizontal) position of the cropping rectangle

crop-y

Y (vertical) position of the cropping rectangle

crop-width

Cropping rectangle width.

crop-height

Cropping rectangle height.

The cropping rectangle size and position may specify locations outside of the original image bounds. In such case, areas outside of image bounds will be left empty or will use the background color, if specified.

Fitting images to size

After the optional cropping step, uploaded images can be resized to specific dimensions. The target dimensions are specified using the following parameters:

Parameter name

Description

fit-width

Fitting rectangle width.

fit-height

Fitting rectangle height.

The method used to arrange the image within the fitting rectangle is determined by the value of the fit parameter:

Fit type

Description

cover

The image is enlarged, if necessary, so that both dimensions of the resulting image are at least as large as the fitting rectangle.

cover-crop

The image is enlarged, if necessary, to ensure that both dimensions are at least as large as the fitting rectangle. It is then cropped to match the size of the fitting rectangle, with any excess parts beyond the target dimensions discarded.

fit

The image is resized—either scaled up or down—so that one dimension (width or height) exactly matches the corresponding dimension of the fitting rectangle. The other dimension is adjusted proportionally, ensuring the aspect ratio is preserved. As a result, the second dimension may be equal to or smaller than the fitting rectangle’s corresponding dimension.

fit-extend

Same as fit, however, if one or both dimensions of the resulting image are smaller than the fitting rectangle, the image is extended to match those dimensions exactly, using either background or transparent color.

contain

The opposite of the cover method: the image is scaled down so that its dimensions fit entirely within the fitting rectangle.

contain-extend

The opposite of the cover method: the image is scaled down so that its dimensions fit entirely within the fitting rectangle. If the resulting image is smaller than the fitting rectangle in one or both dimensions, it is extended to match the rectangle’s dimensions using a background or transparent color.

crop-extend

The canvas is either expanded or cropped to match the desired dimensions, while the image itself remains unchanged in scale. Expanding adds a border (using a background or transparent color), and cropping removes any content outside the specified dimensions.

Adding image background

By default, images are uploaded as-is. However, a background color can be specified using the background parameter to serve as the backdrop for the resulting image.

Advanced functionality

Background removal

The image server can apply an AI model to automatically detect and remove the background from an image. This functionality works best with photographic content but, as with all AI models, may occasionally produce imprecise or unexpected results.

To enable background removal, use the photo-remove-background parameter and set its value to true.

Upload response

After the uploaded image is processed and ingested by the platform, the image server returns a response containing the description of the uploaded image.

For example:

CODE
{
    "name": "~z61L0553D114EMX7AH",
    "imageUrl": "//fx.images.drivecommerce.com/api/v1/image/drive-unit-test/~z61L0553D114EMX7AH",
    "jpgImageUrl": "//fx.images.drivecommerce.com/api/v1/image/drive-unit-test/~z61L0553D114EMX7AH.jpg",
    "pngImageUrl": "//fx.images.drivecommerce.com/api/v1/image/drive-unit-test/~z61L0553D114EMX7AH",
    "width": 1400,
    "height": 1400,
    "density": 72.0
}

Attribute

Description

name

For UGC content, this will be a randomly generated image ID.

For permanent assets, this will be the name originally specified using name parameter.

This name can be used as src parameter when rendering images.

imageUrl

Resulting image URL.

jpgImageUrl

If the uploaded image is fully opaque, a JPEG version will be automatically generated and returned in this attribute.

pngImageUrl

If the uploaded image contained transparent parts, a PNG version will be automatically generated and returned in this attribute.

width

Image width.

height

Image height.

density

Image DPI.

JavaScript errors detected

Please note, these errors can depend on your browser setup.

If this problem persists, please contact our support.