Batch Image Asynchronous Moderation
Update:
Parameter Specification
- Request URL:
https://isafe.ilivedata.com/api/v1/image/batchCheck/async
- Interface description:
Image asynchronous detection interface. After the task is submitted, the image will be detected, and the results will be returned through callbacks. The callback configuration can be configured in the console service configuration or passed in through parameters.
-
Image requirements:
- Supported types: URL, BASE64
- Supported formats: jpg, png, bmp, gif, webp, tiff, heic;
- Supported image size: <10M;
- Description of gif/long image: Automatically cut gif/long image into frame and check, up to 5 images. Gif/long images are billed according to the actual number of screenshots; Definition of long image: images whose ratio of length and width is greater than 5.
-
HTTP request Header:
Header
Value
Description
Content-Type
application/json;charset=UTF-8
Request body type
Accept
application/json;charset=UTF-8
Return type accepted
X-AppId
The only identifier of the project or application.
X-TimeStamp
The UTC timestamp of the request. Timestamps need to be formatted according to W3C standards, for example: 2010-01-31T23:59:59Z. (http://www.w3.org/TR/xmlschema-2/#dateTime)
Authorization
Signature value
-
Request method:POST
-
Request body JSON object:
- Public Parameters
Parameter
Required
Type
Description
images
Required
json array
array length does not exceed 20
-
New Parameters
Parameter
Required
Type
Description
callbackRegion
Optional
String
Callback region: default cn, optional cn, us, ap. If not given or not within the value range, cn will be used by default to initiate the callback.
callbackUrl
Optional
String
Callback url: http protocol
callbackSecretKey
Optional
String
The callback key can be customized. The key needs to be consistent in the callback signature verification method. Otherwise, it cannot be verified whether the callback data has been tampered with.
-
Example of request body:
{
"images": [
{
"id": "abcd",
"type": 1,
"userId": "123",
"image": "http://abc.com/a.jpg",
},
{
"type": 1,
"userId": "123",
"image": " http://abc.com/b.jpg",
}
]
}
-
Request signature:
When the user requests the Image Check API, the request can be signed with the appId and secretKey (obtained from the Console - Service Configuration). When the API receives the request with the signature information, it will verify the signature using the same algorithm, and if the signature is found to be inconsistent, the API will return 401 error to the user.
If the API validation signature is consistent and the user corresponding to the appId has permission to operate the requested resource, the request succeeds, otherwise the API returns 401 error.
- Request Header to send a signature via HTTP
Method: Add a header named Authorization in the request, whose value is the signature value. For example:
Authorization: ****
- Signature calculation method
- Canonicalized Query String:
Convert the request body JSON string to a hexadecimal string (not Base64) by doing sha256 encoding with UTF-8 character encoding.
CanonicalizedQueryString = hex(sha256(jsonBody))
-
Constructs the signed string StringToSign ("\n" stands for ASCII newline character):
StringToSign = HTTPMethod + “\n” +
HostHeaderInLowercase + “\n” +
HTTPRequestURI + “\n” +
CanonicalizedQueryString < Get from previous step> + “\n” +
“X-AppId:” + SAME_APPID_IN_HEADER + “\n” +
“X-TimeStamp:” + SAME_TIMESTAMP_IN_HEADER
The HTTPRequestURI is the absolute path to the request URI, without the request string. If the HTTPRequestURI is empty, also keep a forward slash (/).
The hash-based message authentication code (HMAC) is created using the HMAC-SHA256 protocol and the signature is calculated.
For more information about HMAC, see: https://tools.ietf.org/html/rfc2104。
-
StringToSign as the signature string, secretKey as the secret key and SHA256 as the hash algorithm.
-
Converting the results of the previous step to a BASE64 string.
-
Put the BASE64 string into the Authorization of HTTP request Header.
- Example of signature
Below is an example of appId & secretKey & image.
appId=***
secrectKey=****
image_base64="T2dnUwACAAAAAAAAAAAd8pVTAAAAAGsIvpMBE..."
Below is an example of request type.
{
"type": 2,
"userId": "12345678",
"image": "T2dnUwACAAAAAAAAAAAd8pVTAAAAAGsIvpMBE..."
}
Generate CanonicalizedQueryString
b3ad8e9d16439ccd5e91924d2516bf9592975003f69beff44e56cddf47bd3118
Generate StringToSign
POST
isafe.ilivedata.com
/api/v1/image/check
b3ad8e9d16439ccd5e91924d2516bf9592975003f69beff44e56cddf47bd3118
X-AppId:***
X-TimeStamp:2020-07-31T07:59:03Z
Signatures from HMAC calculations
****
HTTP Response
Content-Type: application/json;charset=UTF-8
The result is in JSON format, please refer to the following example.
- Description of returning json field:
A json array consisting of a single image result json object.
- Single image result json field description:
Parameter
Type
Description
errorCode
Number
Error code: 0 means success
errorMessage
String
Error message
taskId
String
Task ID
-
Response example:
[
{
"id":"abcd",
"errorCode":0,
"taskId":"Telnet-test_99b2bf004d4a4591bfedbba9574e74d4_1702882338368"},
{"errorCode":0,
"taskId":"Telnet-test_d8d58cc2ecf14edaafd18692997a1f67_1702882338368"}
]
Error Code
Http Status code
Error code
Error message
200
0
This field is omitted
405
1004
Method Not Allowed
411
1007
Not Content Length
400
1002
API Not Found
400
1003
Bad Request
401
1102
Unauthorized Client
401
1106
Missing Access Token
401
1107
Invalid Token
401
1108
Expired Token
401
1110
Invalid Client
401
2000
Missing Parameter
401
2001
Invalid Parameter
Parameter Specification
- Request URL:
https://isafe.ilivedata.com/api/v1/image/batchCheck/async
- Interface description:
Image asynchronous detection interface. After the task is submitted, the image will be detected, and the results will be returned through callbacks. The callback configuration can be configured in the console service configuration or passed in through parameters.
-
Image requirements:
- Supported types: URL, BASE64
- Supported formats: jpg, png, bmp, gif, webp, tiff, heic;
- Supported image size: <10M;
- Description of gif/long image: Automatically cut gif/long image into frame and check, up to 5 images. Gif/long images are billed according to the actual number of screenshots; Definition of long image: images whose ratio of length and width is greater than 5.
-
HTTP request Header:
Header | Value | Description |
---|---|---|
Content-Type | application/json;charset=UTF-8 | Request body type |
Accept | application/json;charset=UTF-8 | Return type accepted |
X-AppId | The only identifier of the project or application. | |
X-TimeStamp | The UTC timestamp of the request. Timestamps need to be formatted according to W3C standards, for example: 2010-01-31T23:59:59Z. (http://www.w3.org/TR/xmlschema-2/#dateTime) | |
Authorization | Signature value |
-
Request method:POST
-
Request body JSON object:
- Public Parameters
Parameter | Required | Type | Description |
---|---|---|---|
images | Required | json array | array length does not exceed 20 |
-
New Parameters
Parameter Required Type Description callbackRegion Optional String Callback region: default cn, optional cn, us, ap. If not given or not within the value range, cn will be used by default to initiate the callback. callbackUrl Optional String Callback url: http protocol callbackSecretKey Optional String The callback key can be customized. The key needs to be consistent in the callback signature verification method. Otherwise, it cannot be verified whether the callback data has been tampered with. -
Example of request body:
{ "images": [ { "id": "abcd", "type": 1, "userId": "123", "image": "http://abc.com/a.jpg", }, { "type": 1, "userId": "123", "image": " http://abc.com/b.jpg", } ] }
-
Request signature:
When the user requests the Image Check API, the request can be signed with the appId and secretKey (obtained from the Console - Service Configuration). When the API receives the request with the signature information, it will verify the signature using the same algorithm, and if the signature is found to be inconsistent, the API will return 401 error to the user.
If the API validation signature is consistent and the user corresponding to the appId has permission to operate the requested resource, the request succeeds, otherwise the API returns 401 error.
- Request Header to send a signature via HTTP
Method: Add a header named Authorization in the request, whose value is the signature value. For example:
Authorization: ****
- Signature calculation method
- Canonicalized Query String:
Convert the request body JSON string to a hexadecimal string (not Base64) by doing sha256 encoding with UTF-8 character encoding.
CanonicalizedQueryString = hex(sha256(jsonBody))
-
Constructs the signed string StringToSign ("\n" stands for ASCII newline character):
StringToSign = HTTPMethod + “\n” + HostHeaderInLowercase + “\n” + HTTPRequestURI + “\n” + CanonicalizedQueryString < Get from previous step> + “\n” + “X-AppId:” + SAME_APPID_IN_HEADER + “\n” + “X-TimeStamp:” + SAME_TIMESTAMP_IN_HEADER
The HTTPRequestURI is the absolute path to the request URI, without the request string. If the HTTPRequestURI is empty, also keep a forward slash (/).
The hash-based message authentication code (HMAC) is created using the HMAC-SHA256 protocol and the signature is calculated.
For more information about HMAC, see: https://tools.ietf.org/html/rfc2104。
-
StringToSign as the signature string, secretKey as the secret key and SHA256 as the hash algorithm.
-
Converting the results of the previous step to a BASE64 string.
-
Put the BASE64 string into the Authorization of HTTP request Header.
- Example of signature
Below is an example of appId & secretKey & image.
appId=***
secrectKey=****
image_base64="T2dnUwACAAAAAAAAAAAd8pVTAAAAAGsIvpMBE..."
Below is an example of request type.
{
"type": 2,
"userId": "12345678",
"image": "T2dnUwACAAAAAAAAAAAd8pVTAAAAAGsIvpMBE..."
}
Generate CanonicalizedQueryString
b3ad8e9d16439ccd5e91924d2516bf9592975003f69beff44e56cddf47bd3118
Generate StringToSign
POST
isafe.ilivedata.com
/api/v1/image/check
b3ad8e9d16439ccd5e91924d2516bf9592975003f69beff44e56cddf47bd3118
X-AppId:***
X-TimeStamp:2020-07-31T07:59:03Z
Signatures from HMAC calculations
****
HTTP Response
Content-Type: application/json;charset=UTF-8
The result is in JSON format, please refer to the following example.
- Description of returning json field:
A json array consisting of a single image result json object.
- Single image result json field description:
Parameter |
Type |
Description |
---|---|---|
errorCode | Number | Error code: 0 means success |
errorMessage | String | Error message |
taskId | String | Task ID |
-
Response example:
[ { "id":"abcd", "errorCode":0, "taskId":"Telnet-test_99b2bf004d4a4591bfedbba9574e74d4_1702882338368"}, {"errorCode":0, "taskId":"Telnet-test_d8d58cc2ecf14edaafd18692997a1f67_1702882338368"} ]
Error Code
Http Status code | Error code | Error message |
---|---|---|
200 | 0 | This field is omitted |
405 | 1004 | Method Not Allowed |
411 | 1007 | Not Content Length |
400 | 1002 | API Not Found |
400 | 1003 | Bad Request |
401 | 1102 | Unauthorized Client |
401 | 1106 | Missing Access Token |
401 | 1107 | Invalid Token |
401 | 1108 | Expired Token |
401 | 1110 | Invalid Client |
401 | 2000 | Missing Parameter |
401 | 2001 | Invalid Parameter |