You can call this operation to add a sample image to a specified similar-image library.
Usage notes
API operation: /green/similarity/image/add
When you add a sample image, you can set tags for the image. If the sample image is hit during a search, its tags are also returned.
New sample images take effect within one minute.
The images to be moderated must meet the following requirements:
The URLs of images must be HTTP or HTTPS URLs.
The images must be in PNG, JPG, JPEG, BMP, GIF, or WEBP format.
An image can be up to 20 MB in size. The limit for the image size is applicable to both synchronous and asynchronous moderation operations.
, The height or width cannot exceed30,000pixels (px), and the total pixels of the image cannot exceed2.5 hundred million (px)
Notewhere, GIFformat images, the total pixels of the image cannot exceed4,194,304(px), The height or width cannot exceed30,000pixels (px).
The duration for downloading an image is limited to 3 seconds. If an image fails to be downloaded within 3 seconds, a timeout error is returned.
We recommend that you submit images of at least 256 × 256 pixels to ensure the moderation effect.
The response time of an operation for moderating images varies based on the duration for downloading these images. Make sure that you use a stable and reliable storage service to store the images to be moderated. We recommend that you use Object Storage Service (OSS) or Content Delivery Network (CDN).
QPS limits
You can call this operation up to 20 times per second per account. If the number of calls per second exceeds the limit, throttling is triggered. As a result, your business may be affected. We recommend that you take note of the limit when you call this operation.
Request parameters
| Name | Type | Required | Example | Description |
| tasks | JSONArray | Yes | The detection objects. Each element in the JSON array is a task struct. You can specify up to 100 elements to submit 100 items for detection in each request. To specify 100 elements, you must set the number of concurrent tasks to 100 or more. For more information about the struct of each element, see task. | |
| library | String | No | test | The name of the image library to manage. If you do not specify this parameter, the sample image is added to the default library. The name of the default library is `default`. |
| Name | Type | Required | Example | Description |
| dataId | String | No | 1 | The unique ID of the sample in your business system. For example, you can set the sample ID to "1" or "s-001". |
| url | String | Yes | http://example.com/1.jpg | The URL of the sample image. |
| tags | JSONArray | No | ["pornography","politics"] | The tags to set for the sample image. Each element is a string. You can set a maximum of three tag values. For example, you can add the following tags to a sample image: ["pornography", "politics"]. Note If this sample is hit, the corresponding tag information is returned. |
Return Data
| Name | Type | Example | Description |
| code | Integer | 200 | The returned HTTP status code. For more information, see Common error codes. |
| msg | String | OK | The response message for the request. |
| dataId | String | 1 | This corresponds to the dataId in the request. |
| url | String | http://example.com/1.jpg | This corresponds to the url in the request. |
Examples
Sample request
http(s)://[Endpoint]/green/similarity/image/add
&<Common request parameters>
{
"tasks": [
{
"dataId": "1",
"url": "http://example.com/1.jpg",
"tags": [
"pornography",
"politics"
]
},
{
"dataId": "2",
"url": "http://example.com/2.jpg",
"tags": [
"pornography",
"politics"
]
}
],
"library": "test"
}Sample response
{
"msg": "OK",
"code": 200,
"requestId": "33921869-CF8A-4E62-8C31-44F37341FFC1",
"data": [
{
"code": 200,
"msg": "OK",
"dataId": "1",
"url": "http://example.com/1.jpg"
},
{
"code": 200,
"msg": "OK",
"dataId": "2",
"url": "http://example.com/2.jpg"
}
]
}