All Products
Search
Document Center

Add an image

Last Updated: Jul 24, 2019

Description

You can call this operation to add images to an Image Search instance.

Request URL

Protocol URL Method Parameter
HTTPS ${HOST}/v2/image/add POST JSON

For more information about ${HOST}, see Request structure.

Request parameters

Name Type Required Description
InstanceName String Yes The name of the Image Search instance.
ProductId String Yes The ID of the product. Length constraint: Minimum length of 512 characters.
Note: A product can have multiple images.
PicName String Yes The name of the image. Length constraint: Minimum length of 512 characters.
Note:
1. A specific image is identified based on ProductId and PicName.
2. If you add multiple images with the same ProductId and PicName, the last add operation prevails and the previous operations are overwritten.
PicContent String Yes The image content, which is encoded by using Base64. A maximum image of 2 MB and a 5s transmission wait time are supported. Currently, only JPG and PNG images are supported. The image length and width must be greater than or equal to 200 pixels and smaller than or equal to 1024 pixels. The image cannot contain rotation information.
CategoryId Integer No The image category. For more information, see Category reference.
Notes:
1. For product search: If a category is configured, the configured category prevails. If no category is configured, a category prediction is performed. The predicted category results can be obtained in the response.
2. For generic search: The parameter value is set to 88888888 regardless of whether a category is set.
Crop Boolean No Indicates whether subject recognition is required. Default value: true.
Notes:
1. If the parameter is set to true, the system identifies the subject and searches for the identified subject. The subject recognition result is included in the response.
2. If this parameter is set to false, the entire image is searched for without subject recognition.
Region String No The subject area of the image, in the format of x1,x2,y1,y2. Specifically, x1 and y1 determine the point in the upper-left corner, and x2 and y2 determine the point in the lower-right corner.
Note: If you set the Region parameter, the search is conducted based on this parameter regardless of the value of the Crop parameter.
CustomContent String No The user-defined content. Length constraint: Minimum length of 4,096 characters.
Note: This parameter is returned when you send a query request. You can add text, such as an image description.
IntAttr Integer No The integer type attribute, which can be used for filtering during queries. This parameter is returned when you send a query request.
Note: For example, you can set different IntAttr values for images of different sites or images of different users, and filter the images to implement image isolation during queries.
StrAttr String No The string type attribute. Length constraint: Minimum length of 128 characters. This parameter can be used for filtering during queries. It is returned when you send a query request.

Response parameters

Name Type Example Description
Success Boolean true Indicates whether the call is successful. A value of true indicates that the call is successful. A value of false indicates that the call has failed.
RequestId String 36C43E96-8F68-44AA-B1AF-B1F7AB94A6C1 The request ID.
Code Integer 0 The error code. A value of 0 indicates that the call is successful. Other values indicate that the call has failed.
Message String success The error message.
PicInfo The results of category prediction and subject recognition.
└ CategoryId Integer 88888888 The result of category prediction. If a category is specified in the request, the specified category takes effect.
└ Region String 280,486,232,351 The result of subject recognition. The subject area of the image, in the format of x1,x2,y1,y2. Specifically, x1 and y1 determine the point in the upper-left corner, and x2 and y2 determine the point in the lower-right corner. If the subject area is specified in the request, the specified subject area takes effect.

Examples

Sample requests

  1. URL: ${HOST}/v2/image/add
  2. POST Body:
  3. {
  4. "InstanceName": "demoinstance",
  5. "Name": "test",
  6. "CustomContent": "demo content",
  7. "PicContent": "${Base64ImageContent}",
  8. "ProductId": "test",
  9. "IntAttr": "0",
  10. "StrAttr": "demo str attr"
  11. }

Sample responses

  1. {
  2. "PicInfo": {
  3. "Region": "111,697,113,774",
  4. "CategoryId": 0
  5. },
  6. "Message": "success",
  7. "RequestId": "B253A127-DF89-4DDC-A295-618DD22B00B2",
  8. "Success": true,
  9. "Code": 0
  10. }

Error codes

For more information, see Error codes.