All Products
Search
Document Center

Image Search:Add images

Last Updated:Oct 30, 2023

Adds images to an Image Search instance.

Before you call this operation, you must specify the instanceName parameter in the URL to specify the instance to which you want to add images. You must also specify other parameters in a specified format to construct the request body. The request URL includes /item/add.

Request parameters

  • Parameters in the URL

    Parameter

    Type

    Required

    Description

    instanceName

    String

    Yes

    The name of the Image Search instance. The name can be up to 20 characters in length.

    If an Image Search instance is purchased, you can log on to the Image Search console to view the instance.

    If no Image Search instance is purchased, you must purchase an instance. For more information, see Activate Image Search and Create an instance.

    Note

    The instance name is not the instance ID.

  • Parameters in the request body

    Parameter

    Type

    Required

    Description

    item_id

    String

    Yes

    The ID of the product or the image.

    cat_id

    String

    • For product image searches, this parameter is required.

    • For generic image searches, this parameter is optional.

    The ID of the category.

    crop

    boolean

    No

    Specifies whether to recognize the subject in the image and search for images based on the recognized subject. Valid values: true and false. Default value: true.

    region

    String

    No

    The subject area in the image. The subject area is in the format of x1,x2,y1,y2. x1 and y1 represent the upper-left corner pixel. x2 and y2 represent the lower-right pixel. By default, the system automatically recognizes the subject area.

    cust_content

    String

    Yes

    The user-defined content.

    pic_list

    List

    Yes

    The list of image names.

    pic_map

    Map

    Yes

    The content of each image.

  • Body structure

    The body is in the following format:

    key1,key1_start_offset,key1_end_offset#...#keyn,keyn_start_offset,keyn_end_offset^key1_content...keyn_content

    The body is divided into two parts: image metadata and image content, which are separated with a circumflex (^). The metadata includes a set of keys and the offset of each key value in the content. Keys are separated with number signs (#). Each key includes a key name, a start offset value, and an end offset value, which are separated with commas (,). The start offset value and the end offset value represent the start position and end position of the key the image content. The pic_list parameter specifies Base64-encoded image names that are separated with commas (,). The pic_map parameter specifies Base64-encoded image content. Each key that is specified in the pic_map parameter must be paired with a key that is specified in the pic_list parameter.

Response parameters

Parameter

Type

Description

Success

Boolean

Indicates whether the request is successful.

RequestId

String

The ID of the request.

Code

int

The error code. The value 0 indicates a request success. A value that is not 0 indicates a request failure.

Message

String

The returned message.

Response format

{ "Message":"success", "RequestId":"73B5133C-84EE-4F0A-B972-23CCCBFB7CD5", "Success":true, "Code":0 }

Examples

The following example shows how to add a product image to the Image Search instance named goodssearch. In this example, the value of the item_id parameter is 1000. The value of the cat_id parameter is 0. The value of the cust_content parameter is {"key1":"value1"}. Product images shoes1.jpg and shoes2.jpg are added. The content of the shoes1.jpg image is pic_content1, and the content of the shoes2.jpg image is pic_content2. The following request is provided:

URL: /item/add?instaneName=goodssearch
POST Body:
cust_content,0,17#item_id,17,21#c2hvZXMyLmpwZw==,21,37#cat_id,37,38#pic_list,38,71#c2hvZXMxLmpwZw==,71,87^{"key1":"value1"}1000cGljX2NvbnRlbnQy0c2hvZXMyLmpwZw==,c2hvZXMxLmpwZw==cGljX2NvbnRlbnQx
Note: c2hvZXMyLmpwZw== represents the Base64-encoded image name shoes1.jpg and c2hvZXMxLmpwZw== represents the Base64-encoded image name shoes2.jpg.