Node.js SDK
Image Search provides a Node.js SDK with code examples for each API operation.
For more product information and technical support, click Online Consulting or contact us through our DingTalk group (35035130).
API operations
API operation | Description |
Add | Add an image. |
SearchImageByPic | Search by image. |
SearchImageByName | Search by image name. Uses images already added to the index. |
SearchImageByText | Search by text. Available only for product multimodal search. |
SearchImageByFilter | Searches for images using a filter. |
Delete | Delete an image. |
UpdateImage | Update an image. |
Detail | Query instance details. |
DumpMeta | Export metadata. |
DumpMetaList | List metadata export tasks. |
BatchTask | Run a batch task. |
BatchTaskList | List batch tasks. |
CompareSimilarByImage | Compare similarity between two images. |
CheckImageExists | Check whether an image exists. |
Preparations
Before you use the Alibaba Cloud SDK, register an Alibaba Cloud account and create an AccessKey pair. See Create an AccessKey pair.
Install the Image Search Node.js SDK.
npm install @alicloud/imagesearch20201214@4.4.0 --saveAdd operation
Code example
const oss = require('@alicloud/oss-util'); const fs = require('fs'); const imagesearch = require('@alicloud/imagesearch20201214') // For information about how to create an AccessKey pair, see https://help.aliyun.com/document_detail/116401.htm const client = new imagesearch.default({ // An AccessKey pair of an Alibaba Cloud account has permissions to call all API operations. For security, use a Resource Access Management (RAM) user to call API operations or perform routine O&M. // Do not save your AccessKey ID and AccessKey secret in your project code. Otherwise, your AccessKey pair may be leaked and the security of all resources in your account may be compromised. // This example shows how to save the AccessKey ID and AccessKey secret in environment variables. You can also save your AccessKey pair in a configuration file as needed. accessKeyId: process.env.CC_AK_ENV, accessKeySecret: process.env.CC_SK_ENV, type: "access_key", // Replace the value with the region where you purchased the instance. For example, if you purchased an instance in the China (Hangzhou) region, set the endpoint to "imagesearch.cn-hangzhou.aliyuncs.com". endpoint: "imagesearch.cn-shanghai.aliyuncs.com", // The following code shows how to access the service over a VPC. // Note: You can access the service over a VPC only from an ECS instance or a resource that is in the same region as the Image Search instance. For example, if you purchased an Image Search instance in the China (Shanghai) region, your ECS instance or resource must also be in the China (Shanghai) region to access the Image Search service over a VPC. If the call fails, check whether your ECS instance or resource is in the same region as the Image Search instance. // endpointType: "internal", // If you access the Image Search service over a private network, this parameter is required. Set the value to "internal". // endpoint: "imagesearch-vpc.cn-shanghai.aliyuncs.com", // This is the endpoint for VPC access. Replace the value with the region where you purchased the instance. For example, if you purchased an instance in the China (Hangzhou) region, set the endpoint to "imagesearch-vpc.cn-hangzhou.aliyuncs.com". // Replace the value with the region where you purchased the instance. For example, if you purchased an instance in the China (Hangzhou) region, set regionId to "cn-hangzhou". regionId: "cn-shanghai", protocol: 'http' }); var picContent = fs.createReadStream("D:/123.jpg"); async function demo() { const addImageAdvanceRequest = new imagesearch.AddImageAdvanceRequest({ // Required. The name of the Image Search instance. Note that this is the instance name, not the instance ID. You can view the instance name in the Instance Information section of the Image Search console at https://imagesearch.console.aliyun.com/overview. instanceName: "XXXXXXXXXX", // Required. The product ID. The ID can be up to 256 characters in length. // A product can have multiple images. productId: "123455", // Required. The image name. The name can be up to 256 characters in length. // 1. The combination of ProductId and PicName uniquely identifies an image. // 2. If you add an image with the same ProductId and PicName multiple times, the last added image overwrites the previous ones. picName: "this", // The image content. The image can be up to 4 MB in size. The transfer timeout period is 5s. The following image formats are supported: PNG, JPG, JPEG, BMP, GIF, WEBP, TIFF, and PPM. // For product, trademark, and generic image searches, the image height and width must be between 100 pixels and 4,096 pixels. // For cloth searches, the image height and width must be between 448 pixels and 4,096 pixels. // The image cannot contain rotation information. picContentObject: picContent, // Optional. The image category. // 1. For product searches: If you set a category, the specified category is used. If you do not set a category, the system predicts the category. The predicted category is returned in the response. // 2. For cloth, trademark, and generic searches: The system sets the category to 88888888, regardless of whether you specify a category. categoryId : 3, // Optional. The custom content. The content can be up to 4,096 characters in length. // This field is returned in the query results. For example, you can add a text description of the image. customContent : "this is a simple test", // Optional. The integer attribute. You can use this attribute to filter images during a search. This field is returned in the query results. // For example, you can set different IntAttr values for images from different sites or users to isolate them during searches. intAttr : 56, // Optional. The string attribute. The attribute can be up to 128 characters in length. You can use this attribute to filter images during a search. This field is returned in the query results. strAttr : "test", // Optional. Specifies whether to perform subject identification. The default value is true. // 1. If set to true, the system performs subject identification and searches for the identified subject. The identification result is returned in the response. // 2. If set to false, the system does not perform subject identification and searches for the entire image. // 3. For cloth image searches, this parameter is ignored, and the system searches for the entire image. crop : true, // Optional. The subject region of the image. The format is x1,x2,y1,y2. (x1, y1) are the coordinates of the upper-left corner, and (x2, y2) are the coordinates of the lower-right corner. The specified region cannot exceed the image boundaries. // If you specify a region, the system searches based on the specified region, regardless of the value of the Crop parameter. // For cloth image searches, this parameter is ignored, and the system searches for the entire image. region : "167,467,221,407" }); let ossRuntime = new oss.RuntimeOptions({}); const addResponse = await client.addImageAdvance(addImageAdvanceRequest, ossRuntime); console.log(1, addResponse); } demo();Response example
AddImageResponse { requestId: 'B85D5B4A-92AF-44C1-A3FB-9B554950F8D1', success: true, message: 'success', code: 0, picInfo: AddImageResponsePicInfo { categoryId: 0, region: '167,477,221,407' } }
SearchImageByPic operation
Code example
const oss = require('@alicloud/oss-util'); const fs = require('fs'); const imagesearch = require('@alicloud/imagesearch20201214') // For information about how to create an AccessKey pair, see https://help.aliyun.com/document_detail/116401.htm. const client = new imagesearch.default({ // An AccessKey pair for an Alibaba Cloud account can call all API operations. For security, we recommend that you use a RAM user to call API operations or perform routine O&M. // Important: We recommend that you do not save your AccessKey ID and AccessKey Secret in your project code to prevent your AccessKey pair from being leaked, which would compromise the security of all your resources. // This example shows how to save the AccessKey ID and AccessKey Secret in environment variables. You can also save them in a configuration file. accessKeyId: process.env.CC_AK_ENV, accessKeySecret: process.env.CC_SK_ENV, type: "access_key", // Replace the value with the region where you purchased the instance. For example, if you purchased an instance in the China (Hangzhou) region, set the endpoint to "imagesearch.cn-hangzhou.aliyuncs.com". endpoint: "imagesearch.cn-shanghai.aliyuncs.com", // The following code shows how to access the service over a VPC. // Note: To access Image Search over a private network (VPC), your client (such as an ECS instance) and your Image Search instance must be in the same region. Otherwise, calls will fail. // endpointType : "internal", // This parameter is required if you access the Image Search service over a private network. Set the value to "internal". // endpoint : "imagesearch-vpc.cn-shanghai.aliyuncs.com", // This is the endpoint for private network (VPC) access. Replace the value with the region where you purchased the instance. For example, if you purchased an instance in the China (Hangzhou) region, set the endpoint to "imagesearch-vpc.cn-hangzhou.aliyuncs.com". // Replace the value with the region where you purchased the instance. For example, if you purchased an instance in the China (Hangzhou) region, set regionId to "cn-hangzhou". regionId: "cn-shanghai", protocol: 'http' }); var picContent = fs.createReadStream("D:/123.jpg"); async function demo() { const searchImageByPicAdvanceRequest = new imagesearch.SearchImageByPicAdvanceRequest({ // Required. The name of the Image Search instance. Note: This is the instance name, not the instance ID. You can find the instance name in the Instance Information section of the Image Search console: https://imagesearch.console.aliyun.com/overview instanceName: "XXXXXXXX", // The image content, up to 4 MB in size. The transfer times out after 5 seconds. The following image formats are supported: PNG, JPG, JPEG, BMP, GIF, WEBP, TIFF, and PPM. // For product, trademark, and generic image search, the image height and width must be from 100 to 4,096 pixels. // For fabric search, the image height and width must be from 448 to 4,096 pixels. // The image cannot contain rotation information. picContentObject: picContent, // Optional. The product category. // 1. For product search: If you specify a category, the service uses it. If you do not specify a category, the system predicts one. The predicted category is returned in the response. // 2. For fabric, trademark, and generic search: The system sets the category to 88888888 regardless of whether you specify a category. categoryId: 3, // Optional. The number of results to return. Valid values: 1 to 100. Default value: 10. num: 10, // Optional. The starting position of the results to return. Valid values: 0 to 499. Default value: 0. start: 0, // Optional. Specifies whether to perform subject identification. Default value: true. // 1. If this parameter is set to true, the system performs subject identification and searches based on the identified subject. The identification results are returned in the response. // 2. If this parameter is set to false, the system does not perform subject identification and searches the entire image. // 3. For fabric image search, this parameter is ignored, and the system searches the entire image. crop: true, // Optional. The subject region of the image, in `x1,x2,y1,y2` format. `(x1, y1)` specifies the coordinates of the upper-left corner, and `(x2, y2)` specifies the coordinates of the lower-right corner. The specified region cannot exceed the image boundaries. // If you specify a region, the system searches based on the specified region, regardless of the value of the crop parameter. region: "167,467,221,407", // Optional. The filter condition. // The following operators are supported for int_attr: in, not in, >, >=, <, <=, and =. The following operators are supported for str_attr: in, not in, =, and !=. You can use AND and OR to connect multiple conditions. // Examples: // 1. Filter by IntAttr: int_attr>=100 // 2. Filter by StrAttr: str_attr!="value1" // 3. Filter by both IntAttr and StrAttr: int_attr=1000 AND str_attr="value1" filter: "int_attr=56 AND str_attr =\"test\"", // Optional. The similarity score threshold. // If specified, only images with a similarity score greater than or equal to the threshold are returned. The value can range from 0.00 to 1.00 and supports up to two decimal places. The default value is 0.00. scoreThreshold: "0.54", // Optional. If set to `true`, the service groups the response data by `ProductId`. distinctProductId: false }); let ossRuntime = new oss.RuntimeOptions({}); const searchImageByPicResponse = await client.searchImageByPicAdvance(searchImageByPicAdvanceRequest, ossRuntime); console.log(3, searchImageByPicResponse); } demo();Response example
SearchImageByPicResponse { requestId: 'A38BFBD4-D7AD-4BE9-9606-72BB765A9001', success: true, code: 0, msg: 'success', auctions: [ SearchImageByPicResponseAuctions { categoryId: 0, productId: '1000', picName: 'vae.jpg', score:1.0, sortExprValues: '7.33136443711219e+24;0' }, ............... SearchImageByPicResponseAuctions { categoryId: 0, productId: '123455', picName: 'this', score:1.0, sortExprValues: '7.33136443711219e+24;0' } ], head: SearchImageByPicResponseHead { docsReturn: 5, docsFound: 5, searchTime: 218 }, picInfo: SearchImageByPicResponsePicInfo { categoryId: 0, region: '167,477,221,407', allCategories: [ [SearchImageByPicResponsePicInfoAllCategories], ........ [SearchImageByPicResponsePicInfoAllCategories] ], "multiRegion": [ [SearchImageByPicResponseBodyPicInfoMultiRegion], ........ [SearchImageByPicResponseBodyPicInfoMultiRegion] ] } }
SearchImageByName operation
Code example
const oss = require('@alicloud/oss-util'); const fs = require('fs'); const imagesearch = require('@alicloud/imagesearch20201214') // For information about how to create an AccessKey pair, see https://help.aliyun.com/document_detail/116401.htm const client = new imagesearch.default({ // An AccessKey pair of an Alibaba Cloud account has permissions to call all API operations. For security, use a RAM user to call API operations or perform routine O&M. // Do not save your AccessKey ID and AccessKey secret in your project code. Otherwise, your AccessKey pair may be leaked and the security of all resources in your account may be compromised. // This example shows how to save the AccessKey ID and AccessKey secret in environment variables. You can also save your AccessKey pair in a configuration file as needed. accessKeyId: process.env.CC_AK_ENV, accessKeySecret: process.env.CC_SK_ENV, type: "access_key", // Replace the value with the region where you purchased the instance. For example, if you purchased an instance in the China (Hangzhou) region, set the endpoint to "imagesearch.cn-hangzhou.aliyuncs.com". endpoint: "imagesearch.cn-shanghai.aliyuncs.com", // The following code shows how to access the service over a VPC. // Note: You can access the service over a VPC only from an ECS instance or a resource that is in the same region as the Image Search instance. For example, if you purchased an Image Search instance in the China (Shanghai) region, your ECS instance or resource must also be in the China (Shanghai) region to access the Image Search service over a VPC. If the call fails, check whether your ECS instance or resource is in the same region as the Image Search instance. // endpointType: "internal", // If you access the Image Search service over a private network, this parameter is required. Set the value to "internal". // endpoint: "imagesearch-vpc.cn-shanghai.aliyuncs.com", // This is the endpoint for VPC access. Replace the value with the region where you purchased the instance. For example, if you purchased an instance in the China (Hangzhou) region, set the endpoint to "imagesearch-vpc.cn-hangzhou.aliyuncs.com". // Replace the value with the region where you purchased the instance. For example, if you purchased an instance in the China (Hangzhou) region, set regionId to "cn-hangzhou". regionId: "cn-shanghai", protocol: 'http' }); var picContent = fs.createReadStream("D:/123.jpg"); async function demo() { const searchImageByNameRequest = new imagesearch.SearchImageByNameRequest({ // Required. The name of the Image Search instance. Note that this is the instance name, not the instance ID. You can view the instance name in the Instance Information section of the Image Search console at https://imagesearch.console.aliyun.com/overview. instanceName: "XXXXXXX", // Required. The product ID. The ID can be up to 256 characters in length. // A product can have multiple images. productId: "123455", // Required. The image name. The name can be up to 256 characters in length. // 1. The combination of ProductId and PicName uniquely identifies an image. picName: "this", // Optional. The product category. // 1. For product searches: If you set a category, the specified category is used. If you do not set a category, the system predicts the category. The predicted category is returned in the response. // 2. For cloth, trademark, and generic searches: The system sets the category to 88888888, regardless of whether you specify a category. categoryId: 3, // Optional. The number of results to return. Value range: 1 to 100. Default value: 10. num: 10, // Optional. The starting position of the results to return. Value range: 0 to 499. Default value: 0. start: 0, // Optional. Specifies whether to perform subject identification. The default value is true. // 1. If set to true, the system performs subject identification and searches for the identified subject. The identification result is returned in the response. // 2. If set to false, the system does not perform subject identification and searches for the entire image. // 3. For cloth image searches, this parameter is ignored, and the system searches for the entire image. crop: true, // Optional. The filter condition. // The following operators are supported for int_attr: in, not in, >, >=, <, <=, and =. The following operators are supported for str_attr: in, not in, =, and !=. You can use AND and OR to connect multiple conditions. // Examples: // 1. Filter by IntAttr: int_attr>=100 // 2. Filter by StrAttr: str_attr!="value1" // 3. Filter by both IntAttr and StrAttr: int_attr=1000 AND str_attr="value1" filter: "int_attr=56 AND str_attr =\"test\"", // Optional. The similarity score threshold. // After you specify a threshold, only images with a similarity score greater than or equal to the threshold are returned. The value ranges from 0.00 to 1.00 and supports up to two decimal places. The default value is 0.00. scoreThreshold: "0.54" }); const searchImageByNameResponse = await client.searchImageByName(searchImageByNameRequest); console.log(2, searchImageByNameResponse); } demo();Response example
SearchImageByNameResponse { requestId: '4B039098-B274-41DE-9A55-32550B6F74E1', success: true, code: 0, msg: 'success', auctions: [ SearchImageByNameResponseAuctions { categoryId: 0, productId: '1000', picName: 'vae.jpg', score:1.0, sortExprValues: '7.33136443711219e+24;0' }, ......... SearchImageByNameResponseAuctions { categoryId: 0, productId: '123455', picName: 'this', score:1.0, sortExprValues: '7.33136443711219e+24;0' } ], head: SearchImageByNameResponseHead { docsReturn: 5, docsFound: 5, searchTime: 11 }, picInfo: SearchImageByNameResponsePicInfo { categoryId: 0, allCategories: [ [SearchImageByNameResponsePicInfoAllCategories], ...... [SearchImageByNameResponsePicInfoAllCategories] ], "multiRegion": [ [SearchImageByPicResponseBodyPicInfoMultiRegion], ........ [SearchImageByPicResponseBodyPicInfoMultiRegion] ] } }
SearchImageByText operation
The SearchImageByText operation is available only for multimodal product search instances.
Code example
const oss = require('@alicloud/oss-util'); const fs = require('fs'); const imagesearch = require('@alicloud/imagesearch20201214') // For information about how to create an AccessKey pair, see https://help.aliyun.com/document_detail/116401.htm const client = new imagesearch.default({ // An AccessKey pair of an Alibaba Cloud account has permissions to call all API operations. For security, use a RAM user to call API operations or perform routine O&M. // Do not save your AccessKey ID and AccessKey secret in your project code. Otherwise, your AccessKey pair may be leaked and the security of all resources in your account may be compromised. // This example shows how to save the AccessKey ID and AccessKey secret in environment variables. You can also save your AccessKey pair in a configuration file as needed. accessKeyId: process.env.CC_AK_ENV, accessKeySecret: process.env.CC_SK_ENV, type: "access_key", // Replace the value with the region where you purchased the instance. For example, if you purchased an instance in the China (Hangzhou) region, set the endpoint to "imagesearch.cn-hangzhou.aliyuncs.com". endpoint: "imagesearch.cn-shanghai.aliyuncs.com", // The following code shows how to access the service over a VPC. // Note: You can access the service over a VPC only from an ECS instance or a resource that is in the same region as the Image Search instance. For example, if you purchased an Image Search instance in the China (Shanghai) region, your ECS instance or resource must also be in the China (Shanghai) region to access the Image Search service over a VPC. If the call fails, check whether your ECS instance or resource is in the same region as the Image Search instance. // endpointType: "internal", // If you access the Image Search service over a private network, this parameter is required. Set the value to "internal". // endpoint: "imagesearch-vpc.cn-shanghai.aliyuncs.com", // This is the endpoint for VPC access. Replace the value with the region where you purchased the instance. For example, if you purchased an instance in the China (Hangzhou) region, set the endpoint to "imagesearch-vpc.cn-hangzhou.aliyuncs.com". // Replace the value with the region where you purchased the instance. For example, if you purchased an instance in the China (Hangzhou) region, set regionId to "cn-hangzhou". regionId: "cn-shanghai", protocol: 'http' }); async function demo() { const SearchImageByTextRequest = new imagesearch.SearchImageByTextRequest({ // Required. The name of the Image Search instance. Note that this is the instance name, not the instance ID. You can view the instance name in the Instance Information section of the Image Search console at https://imagesearch.console.aliyun.com/overview. // Note: This API operation is available only for multimodal product search instances. instanceName: "XXXXXXX", // Optional. The number of results to return. Value range: 1 to 100. Default value: 10. num: 10, // Optional. The starting position of the results to return. Value range: 0 to 499. Default value: 0. start: 0, // Optional. The filter condition. // The following operators are supported for int_attr: in, not in, >, >=, <, <=, and =. The following operators are supported for str_attr: in, not in, =, and !=. You can use AND and OR to connect multiple conditions. // Examples: // 1. Filter by IntAttr: int_attr>=100 // 2. Filter by StrAttr: str_attr!="value1" // 3. Filter by both IntAttr and StrAttr: int_attr=1000 AND str_attr="value1" filter: "int_attr=56 AND str_attr =\"test\"", // Optional. The similarity score threshold. // After you specify a threshold, only images with a similarity score greater than or equal to the threshold are returned. The value ranges from 0.00 to 1.00 and supports up to two decimal places. The default value is 0.00. scoreThreshold: "0.54", // The descriptive text. Chinese and English are supported. The text can be up to 512 characters in length. text: "xxxxx" }); const SearchImageByTextResponse = await client.searchImageByText(SearchImageByTextRequest); console.log(2, SearchImageByTextResponse); } demo();Response example
SearchImageByNameResponse { requestId: '4B039098-B274-41DE-9A55-32550B6F74E1', success: true, code: 0, msg: 'success', auctions: [ SearchImageByNameResponseAuctions { categoryId: 0, productId: '1000', picName: 'vae.jpg', score:1.0 }, ......... SearchImageByNameResponseAuctions { categoryId: 0, productId: '123455', picName: 'this', score:1.0 } ], head: SearchImageByNameResponseHead { docsReturn: 5, docsFound: 5, searchTime: 11 }, picInfo: SearchImageByNameResponsePicInfo { allCategories: [ [SearchImageByNameResponsePicInfoAllCategories], ...... [SearchImageByNameResponsePicInfoAllCategories] ] } }
SearchImageByFilter API
Code example
const oss = require('@alicloud/oss-util'); const imagesearch = require('@alicloud/imagesearch20201214') // To learn how to create an AccessKey pair, see https://help.aliyun.com/document_detail/116401.htm. const client = new imagesearch.default({ // An AccessKey pair from an Alibaba Cloud account can call all API operations. For security, we recommend that you use a RAM user to call API operations or perform routine O&M. // Do not save your AccessKey ID and AccessKey Secret in your project code. Leaking them compromises the security of all your resources. // This example shows how to save the AccessKey ID and AccessKey Secret in an environment variable. You can also save your AccessKey pair in a configuration file. accessKeyId: process.env.CC_AK_ENV, accessKeySecret: process.env.CC_SK_ENV, type: "access_key", // Replace the value with the endpoint for your instance's region. For example, if you purchased an instance in the China (Hangzhou) region, set the endpoint to "imagesearch.cn-hangzhou.aliyuncs.com". endpoint: "imagesearch.cn-shanghai.aliyuncs.com", // The following code provides an example of how to access the service over a private network (VPC). // Note: To access Image Search over a VPC, your client (e.g., an ECS instance) and your Image Search instance must be in the same region. Otherwise, the call will fail. // endpointType : "internal", // Required for private network (VPC) access. Set the value to "internal". // endpoint : "imagesearch-vpc.cn-shanghai.aliyuncs.com", // The endpoint for private network (VPC) access. Replace this with the endpoint for your instance's region. For example, if you purchased an instance in the China (Hangzhou) region, set the endpoint to "imagesearch-vpc.cn-hangzhou.aliyuncs.com". // Replace the value with your instance's region ID. For example, if you purchased an instance in the China (Hangzhou) region, set regionId to "cn-hangzhou". regionId: "cn-shanghai", protocol: 'http' }); async function demo() { const searchImageByFilterRequest = new imagesearch.SearchImageByFilterRequest({ // Required. The name of the Image Search instance. Note: This is the instance name, not the instance ID. After purchasing an instance, you can find the instance name in the Instance Information section of the Image Search console: https://imagesearch.console.aliyun.com/overview instanceName: "XXXXXXXX", num: 10, // Optional. The starting position in the result set. Valid values: 0 to 499. Default value: 0. start: 0, // Required. The filter condition. // The following operators are supported for int_attr: in, not in, >, >=, <, <=, and =. The following operators are supported for str_attr: in, not in, =, and !=. You can use AND and OR to connect multiple conditions. // Examples: // 1. Filter by IntAttr: int_attr>=100 // 2. Filter by StrAttr: str_attr!="value1" // 3. Filter by both IntAttr and StrAttr: int_attr=1000 AND str_attr="value1" filter: "int_attr=56 AND str_attr =\"test\"" }); const searchImageByFilterResponse = await client.searchImageByFilter(searchImageByFilterRequest); console.log(3, searchImageByFilterResponse); } demo();Response example
searchImageByFilterResponse { requestId: 'xx-D7AD-xx-9606-72BB765A9001', success: true, code: 0, msg: 'success', auctions: [ ] }
Delete operation
Code example
const oss = require('@alicloud/oss-util'); const fs = require('fs'); const imagesearch = require('@alicloud/imagesearch20201214') // For information about how to create an AccessKey pair, see https://help.aliyun.com/document_detail/116401.htm. const client = new imagesearch.default({ // An AccessKey pair for an Alibaba Cloud account can call all API operations. For security, we recommend using a RAM user for API calls and routine O&M. // Do not store your AccessKey ID and AccessKey secret in your project code. If you do, your AccessKey pair could be leaked, compromising the security of all your resources. // This example shows how to save the AccessKey ID and AccessKey secret in environment variables. You can also save your AccessKey pair in a configuration file based on your business needs. accessKeyId: process.env.CC_AK_ENV, accessKeySecret: process.env.CC_SK_ENV, type: "access_key", // Replace this with the endpoint for your instance's region. For example, if you purchased an instance in China (Hangzhou), set the endpoint to "imagesearch.cn-hangzhou.aliyuncs.com". endpoint: "imagesearch.cn-shanghai.aliyuncs.com", // The following code shows how to access the service over a VPC. // Note: You can access the Image Search service over a VPC only from an ECS instance or a resource that is in the same region as the Image Search instance. For example, if you purchased an Image Search instance in China (Shanghai), your ECS instance or resource must also be in China (Shanghai) to access the service over a VPC. If the call fails, check whether your ECS instance or resource is in the same region as the Image Search instance. // endpointType: "internal", // This parameter is required if you access the Image Search service over a VPC. Set the value to "internal". // endpoint: "imagesearch-vpc.cn-shanghai.aliyuncs.com", // The endpoint for VPC access. Replace the region in this endpoint with your instance's region. For example, if you purchased an instance in China (Hangzhou), set the endpoint to "imagesearch-vpc.cn-hangzhou.aliyuncs.com". // Replace this with the ID of your instance's region. For example, if you purchased an instance in China (Hangzhou), set regionId to "cn-hangzhou". regionId: "cn-shanghai", protocol: 'http' }); async function demo() { const deleteImageRequest = new imagesearch.DeleteImageRequest({ // Required. The name of the Image Search instance. Note: This is the instance name, not the instance ID. After purchasing an instance, you can find the instance name in the Instance Information section of the Image Search console: https://imagesearch.console.aliyun.com/overview instanceName: "XXXXXXXXXXXXXXXXXX", // Required. The product ID. The ID can be up to 256 characters in length. // A product can have multiple images. productId: "123455", // Optional. The image name. If you omit this parameter, the operation deletes all images associated with the specified productId. If you specify this parameter, the operation deletes only the image identified by the combination of productId and picName. picName: "this", // Optional. If you set this parameter to true, the operation deletes images based on the filter condition or a combination of the filter condition and productId. isDeleteByFilter: false, filter: "intattr3=xxx" }); const deleteImageResponse = await client.deleteImage(deleteImageRequest); console.log(4, deleteImageResponse); } demo();Response example
DeleteImageResponse { requestId: '3965B44B-0584-41DE-8764-0D8B36857CE1', success: true, message: 'success', code: 0 }
UpdateImage operation
Code example
const oss = require('@alicloud/oss-util'); const fs = require('fs'); const imagesearch = require('@alicloud/imagesearch20201214') // To learn how to create an AccessKey pair, see https://help.aliyun.com/document_detail/116401.htm. const client = new imagesearch.default({ // An AccessKey pair for an Alibaba Cloud account grants permissions to call all API operations. For security, we recommend using a RAM user to call API operations or perform routine O&M. // We strongly recommend that you do not store your AccessKey ID and AccessKey Secret in your project code. Otherwise, your AccessKey pair may be leaked, compromising the security of all your resources. // This example shows how to save the AccessKey ID and AccessKey Secret in an environment variable. You can also save your AccessKey pair in a configuration file based on your business needs. accessKeyId: process.env.CC_AK_ENV, accessKeySecret: process.env.CC_SK_ENV, type: "access_key", // Replace the value with the endpoint for the region where you purchased your instance. For example, if you purchased an instance in the China (Hangzhou) region, set the endpoint to "imagesearch.cn-hangzhou.aliyuncs.com". endpoint: "imagesearch.cn-shanghai.aliyuncs.com", // The following code shows how to access the service over a VPC. // Note: You can access Image Search over a VPC only if your client, such as an ECS instance, is in the same region as your Image Search instance. For example, if your Image Search instance is in the China (Shanghai) region, your ECS instance must also be in the China (Shanghai) region to access the Image Search service over a VPC. If a call fails, verify that both resources are in the same region. // endpointType : "internal", // This parameter is required if you access the Image Search service over a VPC. Set the value to "internal". // endpoint : "imagesearch-vpc.cn-shanghai.aliyuncs.com", // This is the endpoint for VPC access. Replace the value with the VPC endpoint for your instance's region. For example, if you purchased an instance in the China (Hangzhou) region, set the endpoint to "imagesearch-vpc.cn-hangzhou.aliyuncs.com". // Replace the value with the ID of your instance's region. For example, if you purchased an instance in the China (Hangzhou) region, set regionId to "cn-hangzhou". regionId: "cn-shanghai", protocol: 'http' }); async function updateImage() { const request = new imagesearch.UpdateImageRequest({ // Required. The name of the Image Search instance. Note: This is the instance name, not the instance ID. After you purchase an instance, you can view the instance name in the Instance Information section of the Image Search console: https://imagesearch.console.aliyun.com/overview instanceName: "XXXXXXXXXXXXXXXXXX", // Required. The product ID. You cannot modify this parameter. productId: "1", // Optional. The image name. If you omit this parameter, the operation updates the attributes for some images that are associated with the product ID. picName: "1", // Optional. The integer attribute. You can use this attribute to filter images during a search. The query results include this field. intAttr: "11", // Optional. The string attribute. The attribute can be up to 128 characters in length. You can use this attribute to filter images during a search. The query results include this field. strAttr: "text", // Optional. The custom content. The content can be up to 4,096 characters in length. customContent: "Test description" }); const response = await client.updateImage(request); console.log(4, response.body.toMap()); } updateImage();Response example
4 { Code: 0, RequestId: '1DD89D33-9D60-179A-9D3E-07CA381F07B5', Success: true }
Detail operation
Code example
const oss = require('@alicloud/oss-util'); const fs = require('fs'); const imagesearch = require('@alicloud/imagesearch20201214') // For information about how to create an AccessKey pair, see https://help.aliyun.com/document_detail/116401.htm const client = new imagesearch.default({ // An AccessKey pair of an Alibaba Cloud account has permissions to call all API operations. For security, use a RAM user to call API operations or perform routine O&M. // Do not save your AccessKey ID and AccessKey secret in your project code. Otherwise, your AccessKey pair may be leaked and the security of all resources in your account may be compromised. // This example shows how to save the AccessKey ID and AccessKey secret in environment variables. You can also save your AccessKey pair in a configuration file as needed. accessKeyId: process.env.CC_AK_ENV, accessKeySecret: process.env.CC_SK_ENV, type: "access_key", // Replace the value with the region where you purchased the instance. For example, if you purchased an instance in the China (Hangzhou) region, set the endpoint to "imagesearch.cn-hangzhou.aliyuncs.com". endpoint: "imagesearch.cn-shanghai.aliyuncs.com", // The following code shows how to access the service over a VPC. // Note: You can access the service over a VPC only from an ECS instance or a resource that is in the same region as the Image Search instance. For example, if you purchased an Image Search instance in the China (Shanghai) region, your ECS instance or resource must also be in the China (Shanghai) region to access the Image Search service over a VPC. If the call fails, check whether your ECS instance or resource is in the same region as the Image Search instance. // endpointType: "internal", // If you access the Image Search service over a private network, this parameter is required. Set the value to "internal". // endpoint: "imagesearch-vpc.cn-shanghai.aliyuncs.com", // This is the endpoint for VPC access. Replace the value with the region where you purchased the instance. For example, if you purchased an instance in the China (Hangzhou) region, set the endpoint to "imagesearch-vpc.cn-hangzhou.aliyuncs.com". // Replace the value with the region where you purchased the instance. For example, if you purchased an instance in the China (Hangzhou) region, set regionId to "cn-hangzhou". regionId: "cn-shanghai", protocol: 'http' }); async function detail() { const request = new imagesearch.DetailRequest({ // Required. The name of the Image Search instance. Note that this is the instance name, not the instance ID. You can view the instance name in the Instance Information section of the Image Search console at https://imagesearch.console.aliyun.com/overview. instanceName: "XXXXXXXXXXXXXXXXXX" }); const response = await client.detail(request); console.log(4, response.body.toMap()); } detail();Response example
4 { Instance: { Capacity: 10, Name: 'xxxxxx', Qps: 1, Region: 'cn-shanghai', ServiceType: 0, TotalCount: 99999, UtcCreate: '1620382716000', UtcExpireTime: '1623081600000' }, RequestId: '84ADF9D3-3668-1837-B0A9-ADB093F77DB2', Success: true }
DumpMeta operation
Code example
const oss = require('@alicloud/oss-util'); const fs = require('fs'); const imagesearch = require('@alicloud/imagesearch20201214') // For information about how to create an AccessKey pair, see https://help.aliyun.com/document_detail/116401.htm const client = new imagesearch.default({ // An AccessKey pair of an Alibaba Cloud account has permissions to call all API operations. For security, use a RAM user to call API operations or perform routine O&M. // Do not save your AccessKey ID and AccessKey secret in your project code. Otherwise, your AccessKey pair may be leaked and the security of all resources in your account may be compromised. // This example shows how to save the AccessKey ID and AccessKey secret in environment variables. You can also save your AccessKey pair in a configuration file as needed. accessKeyId: process.env.CC_AK_ENV, accessKeySecret: process.env.CC_SK_ENV, type: "access_key", // Replace the value with the region where you purchased the instance. For example, if you purchased an instance in the China (Hangzhou) region, set the endpoint to "imagesearch.cn-hangzhou.aliyuncs.com". endpoint: "imagesearch.cn-shanghai.aliyuncs.com", // The following code shows how to access the service over a VPC. // Note: You can access the service over a VPC only from an ECS instance or a resource that is in the same region as the Image Search instance. For example, if you purchased an Image Search instance in the China (Shanghai) region, your ECS instance or resource must also be in the China (Shanghai) region to access the Image Search service over a VPC. If the call fails, check whether your ECS instance or resource is in the same region as the Image Search instance. // endpointType: "internal", // If you access the Image Search service over a private network, this parameter is required. Set the value to "internal". // endpoint: "imagesearch-vpc.cn-shanghai.aliyuncs.com", // This is the endpoint for VPC access. Replace the value with the region where you purchased the instance. For example, if you purchased an instance in the China (Hangzhou) region, set the endpoint to "imagesearch-vpc.cn-hangzhou.aliyuncs.com". // Replace the value with the region where you purchased the instance. For example, if you purchased an instance in the China (Hangzhou) region, set regionId to "cn-hangzhou". regionId: "cn-shanghai", protocol: 'http' }); async function dumpMeta() { const request = new imagesearch.DumpMetaRequest({ // Required. The name of the Image Search instance. Note that this is the instance name, not the instance ID. You can view the instance name in the Instance Information section of the Image Search console at https://imagesearch.console.aliyun.com/overview. instanceName: "XXXXXXXXXXXXXXXXXX" }); const response = await client.dumpMeta(request); console.log(4, response.body.toMap()); } dumpMeta();const oss = require('@alicloud/oss-util'); const fs = require('fs'); const imagesearch = require('@alicloud/imagesearch20201214') // For information about how to create an AccessKey pair, see https://www.alibabacloud.com/help/zh/resource-access-management/latest/accesskey-pairs-create-an-accesskey-pair-for-a-ram-user const client = new imagesearch.default({ // An AccessKey pair of an Alibaba Cloud account has permissions to call all API operations. For security, use a RAM user to call API operations or perform routine O&M. // Do not save your AccessKey ID and AccessKey secret in your project code. Otherwise, your AccessKey pair may be leaked and the security of all resources in your account may be compromised. // This example shows how to save the AccessKey ID and AccessKey secret in environment variables. You can also save your AccessKey pair in a configuration file as needed. accessKeyId: process.env.CC_AK_ENV, accessKeySecret: process.env.CC_SK_ENV, type: "access_key", // Replace the value with the region where you purchased the instance. For example, if you purchased an instance in the Singapore region, set the endpoint to "imagesearch.ap-southeast-1.aliyuncs.com". endpoint: "imagesearch.ap-southeast-1.aliyuncs.com", // The following code shows how to access the service over a VPC. // Note: You can access the service over a VPC only from an ECS instance or a resource that is in the same region as the Image Search instance. For example, if you purchased an Image Search instance in the Singapore region, your ECS instance or resource must also be in the Singapore region to access the Image Search service over a VPC. If the call fails, check whether your ECS instance or resource is in the same region as the Image Search instance. // endpointType: "internal", // If you access the Image Search service over a private network, this parameter is required. Set the value to "internal". // endpoint: "imagesearch-vpc.ap-southeast-1.aliyuncs.com", // This is the endpoint for VPC access. Replace the value with the region where you purchased the instance. For example, if you purchased an instance in the Singapore region, set the endpoint to "imagesearch-vpc.ap-southeast-1.aliyuncs.com". // Replace the value with the region where you purchased the instance. For example, if you purchased an instance in the Singapore region, set regionId to "ap-southeast-1". regionId: "ap-southeast-1", protocol: 'http' }); async function dumpMeta() { const request = new imagesearch.DumpMetaRequest({ // Required. The name of the Image Search instance. Note that this is the instance name, not the instance ID. You can view the instance name in the Instance Information section of the Image Search console at https://imagesearch.console.aliyun.com/overview. instanceName: "XXXXXXXXXXXXXXXXXX" }); const response = await client.dumpMeta(request); console.log(4, response.body.toMap()); } dumpMeta();Response example
4 { Data: { DumpMetaStatus: 'PROCESSING', Id: '571' }, RequestId: '8B639BD9-5EAB-127D-89EF-3EBE3277E02F', Success: true }
DumpMetaList operation
Code example
const oss = require('@alicloud/oss-util'); const fs = require('fs'); const imagesearch = require('@alicloud/imagesearch20201214') // For information about how to create an AccessKey pair, see https://help.aliyun.com/document_detail/116401.htm const client = new imagesearch.default({ // An AccessKey pair of an Alibaba Cloud account has permissions to call all API operations. For security, use a RAM user to call API operations or perform routine O&M. // Do not save your AccessKey ID and AccessKey secret in your project code. Otherwise, your AccessKey pair may be leaked and the security of all resources in your account may be compromised. // This example shows how to save the AccessKey ID and AccessKey secret in environment variables. You can also save your AccessKey pair in a configuration file as needed. accessKeyId: process.env.CC_AK_ENV, accessKeySecret: process.env.CC_SK_ENV, type: "access_key", // Replace the value with the region where you purchased the instance. For example, if you purchased an instance in the China (Hangzhou) region, set the endpoint to "imagesearch.cn-hangzhou.aliyuncs.com". endpoint: "imagesearch.cn-shanghai.aliyuncs.com", // The following code shows how to access the service over a VPC. // Note: You can access the service over a VPC only from an ECS instance or a resource that is in the same region as the Image Search instance. For example, if you purchased an Image Search instance in the China (Shanghai) region, your ECS instance or resource must also be in the China (Shanghai) region to access the Image Search service over a VPC. If the call fails, check whether your ECS instance or resource is in the same region as the Image Search instance. // endpointType: "internal", // If you access the Image Search service over a private network, this parameter is required. Set the value to "internal". // endpoint: "imagesearch-vpc.cn-shanghai.aliyuncs.com", // This is the endpoint for VPC access. Replace the value with the region where you purchased the instance. For example, if you purchased an instance in the China (Hangzhou) region, set the endpoint to "imagesearch-vpc.cn-hangzhou.aliyuncs.com". // Replace the value with the region where you purchased the instance. For example, if you purchased an instance in the China (Hangzhou) region, set regionId to "cn-hangzhou". regionId: "cn-shanghai", protocol: 'http' }); async function dumpMetaList() { const request = new imagesearch.DumpMetaListRequest({ // Required. The name of the Image Search instance. Note that this is the instance name, not the instance ID. You can view the instance name in the Instance Information section of the Image Search console at https://imagesearch.console.aliyun.com/overview. instanceName: "XXXXXXXXXXXXXXXXXX", // Optional. The ID of the metadata export task. id: 567, // Optional. The starting position of the results to return. The default value is 1. pageNumber: 1, // Optional. The number of results to return. The default value is 20. pageSize: 1 }); const response = await client.dumpMetaList(request); console.log(4, response.body.toMap()); console.log(4, response.body.data.dumpMetaList); } dumpMetaList();Response example
4 { Data: { DumpMetaList: [ [Object] ], PageNumber: 1, PageSize: 1, TotalCount: 1 }, RequestId: 'BFE47106-BF23-1581-A3AB-F3F54D8866BC' } 4 [ DumpMetaListResponseBodyDataDumpMetaList { code: '0', id: 567, metaUrl: 'https://xxx/xxx', msg: 'success', status: 'SUCCESS', utcCreate: '1639969113000', utcModified: 1639969140000 } ]
BatchTask operation
Code example
const oss = require('@alicloud/oss-util'); const fs = require('fs'); const imagesearch = require('@alicloud/imagesearch20201214') // For information about how to create an AccessKey pair, see https://help.aliyun.com/document_detail/116401.htm const client = new imagesearch.default({ // An AccessKey pair of an Alibaba Cloud account has permissions to call all API operations. For security, use a RAM user to call API operations or perform routine O&M. // Do not save your AccessKey ID and AccessKey secret in your project code. Otherwise, your AccessKey pair may be leaked and the security of all resources in your account may be compromised. // This example shows how to save the AccessKey ID and AccessKey secret in environment variables. You can also save your AccessKey pair in a configuration file as needed. accessKeyId: process.env.CC_AK_ENV, accessKeySecret: process.env.CC_SK_ENV, type: "access_key", // Replace the value with the region where you purchased the instance. For example, if you purchased an instance in the China (Hangzhou) region, set the endpoint to "imagesearch.cn-hangzhou.aliyuncs.com". endpoint: "imagesearch.cn-shanghai.aliyuncs.com", // The following code shows how to access the service over a VPC. // Note: You can access the service over a VPC only from an ECS instance or a resource that is in the same region as the Image Search instance. For example, if you purchased an Image Search instance in the China (Shanghai) region, your ECS instance or resource must also be in the China (Shanghai) region to access the Image Search service over a VPC. If the call fails, check whether your ECS instance or resource is in the same region as the Image Search instance. // endpointType: "internal", // If you access the Image Search service over a private network, this parameter is required. Set the value to "internal". // endpoint: "imagesearch-vpc.cn-shanghai.aliyuncs.com", // This is the endpoint for VPC access. Replace the value with the region where you purchased the instance. For example, if you purchased an instance in the China (Hangzhou) region, set the endpoint to "imagesearch-vpc.cn-hangzhou.aliyuncs.com". // Replace the value with the region where you purchased the instance. For example, if you purchased an instance in the China (Hangzhou) region, set regionId to "cn-hangzhou". regionId: "cn-shanghai", protocol: 'http' }); async function batchTask() { const request = new imagesearch.IncreaseInstanceRequest({ // Required. The name of the Image Search instance. Note that this is the instance name, not the instance ID. You can view the instance name in the Instance Information section of the Image Search console at https://imagesearch.console.aliyun.com/overview. instanceName: "XXXXXXXXXXXXXXXXXX", // Required. The name of the OSS bucket. bucketName: "xxxx", // Required. The path. The path must start with a forward slash (/) and cannot end with a forward slash (/). // You must prepare the increment.meta file in this path in advance. For more information, see the "Batch Operations" topic in the user guide. path: "/public/xxx", // Optional. The webhook address for successful requests. The address must start with http:// or https://. callbackAddress: "http://xxx/xx" }); const response = await client.increaseInstance(request); console.log(4, response.body.toMap()); } batchTask();Response example
4 { Data: { Id: '1474', IncrementStatus: 'PROCESSING' }, RequestId: 'E2AF05CC-F642-1481-BD97-70DC7EBAF7C8', Success: true }
BatchTaskList operation
Code example
const oss = require('@alicloud/oss-util'); const fs = require('fs'); const imagesearch = require('@alicloud/imagesearch20201214') // For information about how to create an AccessKey pair, see https://help.aliyun.com/document_detail/116401.htm const client = new imagesearch.default({ // An AccessKey pair of an Alibaba Cloud account has permissions to call all API operations. For security, use a RAM user to call API operations or perform routine O&M. // Do not save your AccessKey ID and AccessKey secret in your project code. Otherwise, your AccessKey pair may be leaked and the security of all resources in your account may be compromised. // This example shows how to save the AccessKey ID and AccessKey secret in environment variables. You can also save your AccessKey pair in a configuration file as needed. accessKeyId: process.env.CC_AK_ENV, accessKeySecret: process.env.CC_SK_ENV, type: "access_key", // Replace the value with the region where you purchased the instance. For example, if you purchased an instance in the China (Hangzhou) region, set the endpoint to "imagesearch.cn-hangzhou.aliyuncs.com". endpoint: "imagesearch.cn-shanghai.aliyuncs.com", // The following code shows how to access the service over a VPC. // Note: You can access the service over a VPC only from an ECS instance or a resource that is in the same region as the Image Search instance. For example, if you purchased an Image Search instance in the China (Shanghai) region, your ECS instance or resource must also be in the China (Shanghai) region to access the Image Search service over a VPC. If the call fails, check whether your ECS instance or resource is in the same region as the Image Search instance. // endpointType: "internal", // If you access the Image Search service over a private network, this parameter is required. Set the value to "internal". // endpoint: "imagesearch-vpc.cn-shanghai.aliyuncs.com", // This is the endpoint for VPC access. Replace the value with the region where you purchased the instance. For example, if you purchased an instance in the China (Hangzhou) region, set the endpoint to "imagesearch-vpc.cn-hangzhou.aliyuncs.com". // Replace the value with the region where you purchased the instance. For example, if you purchased an instance in the China (Hangzhou) region, set regionId to "cn-hangzhou". regionId: "cn-shanghai", protocol: 'http' }); async function batchTaskList() { const request = new imagesearch.IncreaseListRequest({ // Required. The name of the Image Search instance. Note that this is the instance name, not the instance ID. You can view the instance name in the Instance Information section of the Image Search console at https://imagesearch.console.aliyun.com/overview. instanceName: "XXXXXXXXXXXXXXXXXX", // Required. The name of the OSS bucket. bucketName: "xxxx", // Required. The path. The path must start with a forward slash (/) and cannot end with a forward slash (/). path: "/public/xxx", // Optional. The ID of the metadata export task. id: 1464, // Optional. The starting position of the results to return. The default value is 1. pageNumber: 1, // Optional. The number of results to return. The default value is 20. pageSize: 1 }); const response = await client.increaseList(request); console.log(4, response.body.toMap()); console.log(4, response.body.data.increments.toMap()); } batchTaskList();Response example
4 { Data: { Increments: { Instance: [Array] }, PageNumber: 1, PageSize: 1, TotalCount: 1 }, RequestId: 'F51B5D0D-3E10-170B-88ED-79997736C6E8' } 4 { Instance: [ { BucketName: 'cccxxx', Code: '0', ErrorUrl: 'https://x/x', Id: 1464, Msg: 'success', Path: '/public/xxx', Status: 'NORMAL', UtcCreate: '1639107872000', UtcModified: 1639125540000 } ] }
CompareSimilarByImage operation
Code example
const oss = require('@alicloud/oss-util'); const fs = require('fs'); const imagesearch = require('@alicloud/imagesearch20201214') // For information about how to create an AccessKey pair, see https://help.aliyun.com/document_detail/116401.htm const client = new imagesearch.default({ // An AccessKey pair of an Alibaba Cloud account has permissions to call all API operations. For security, use a RAM user to call API operations or perform routine O&M. // Do not save your AccessKey ID and AccessKey secret in your project code. Otherwise, your AccessKey pair may be leaked and the security of all resources in your account may be compromised. // This example shows how to save the AccessKey ID and AccessKey secret in environment variables. You can also save your AccessKey pair in a configuration file as needed. accessKeyId: process.env.CC_AK_ENV, accessKeySecret: process.env.CC_SK_ENV, type: "access_key", // Replace the value with the region where you purchased the instance. For example, if you purchased an instance in the China (Hangzhou) region, set the endpoint to "imagesearch.cn-hangzhou.aliyuncs.com". endpoint: "imagesearch.cn-shanghai.aliyuncs.com", // The following code shows how to access the service over a VPC. // Note: You can access the service over a VPC only from an ECS instance or a resource that is in the same region as the Image Search instance. For example, if you purchased an Image Search instance in the China (Shanghai) region, your ECS instance or resource must also be in the China (Shanghai) region to access the Image Search service over a VPC. If the call fails, check whether your ECS instance or resource is in the same region as the Image Search instance. // endpointType: "internal", // If you access the Image Search service over a private network, this parameter is required. Set the value to "internal". // endpoint: "imagesearch-vpc.cn-shanghai.aliyuncs.com", // This is the endpoint for VPC access. Replace the value with the region where you purchased the instance. For example, if you purchased an instance in the China (Hangzhou) region, set the endpoint to "imagesearch-vpc.cn-hangzhou.aliyuncs.com". // Replace the value with the region where you purchased the instance. For example, if you purchased an instance in the China (Hangzhou) region, set regionId to "cn-hangzhou". regionId: "cn-shanghai", protocol: 'http' }); var primaryContent = fs.createReadStream("D:/123.jpg"); var secondaryContent = fs.createReadStream("D:/123.jpg"); async function demo() { const compareSimilarByImageAdvanceRequest = new imagesearch.CompareSimilarByImageAdvanceRequest({ // Required. The name of the Image Search instance. Note that this is the instance name, not the instance ID. You can view the instance name in the Instance Information section of the Image Search console at https://imagesearch.console.aliyun.com/overview. instanceName: "XXXXXXXXXX", primaryPicContentObject: primaryContent, secondaryPicContentObject: secondaryContent }); let ossRuntime = new oss.RuntimeOptions({}); const compareSimilarResponse = await client.compareSimilarByImageAdvance(compareSimilarByImageAdvanceRequest, ossRuntime); console.log(1, compareSimilarResponse); } demo();Response example
compareSimilarResponse { requestId: 'B85D5B4A-92AF-44C1-A3FB-9B554950F8D1', success: true, message: 'success', code: 0, Score: 1 }
CheckImageExists operation
Code example
const oss = require('@alicloud/oss-util'); const fs = require('fs'); const imagesearch = require('@alicloud/imagesearch20201214') // For information about how to create an AccessKey pair, see https://help.aliyun.com/document_detail/116401.htm const client = new imagesearch.default({ // An AccessKey pair of an Alibaba Cloud account has permissions to call all API operations. For security, use a RAM user to call API operations or perform routine O&M. // Do not save your AccessKey ID and AccessKey secret in your project code. Otherwise, your AccessKey pair may be leaked and the security of all resources in your account may be compromised. // This example shows how to save the AccessKey ID and AccessKey secret in environment variables. You can also save your AccessKey pair in a configuration file as needed. accessKeyId: process.env.CC_AK_ENV, accessKeySecret: process.env.CC_SK_ENV, type: "access_key", // Replace the value with the region where you purchased the instance. For example, if you purchased an instance in the China (Hangzhou) region, set the endpoint to "imagesearch.cn-hangzhou.aliyuncs.com". endpoint: "imagesearch.cn-shanghai.aliyuncs.com", // The following code shows how to access the service over a VPC. // Note: You can access the service over a VPC only from an ECS instance or a resource that is in the same region as the Image Search instance. For example, if you purchased an Image Search instance in the China (Shanghai) region, your ECS instance or resource must also be in the China (Shanghai) region to access the Image Search service over a VPC. If the call fails, check whether your ECS instance or resource is in the same region as the Image Search instance. // endpointType: "internal", // If you access the Image Search service over a private network, this parameter is required. Set the value to "internal". // endpoint: "imagesearch-vpc.cn-shanghai.aliyuncs.com", // This is the endpoint for VPC access. Replace the value with the region where you purchased the instance. For example, if you purchased an instance in the China (Hangzhou) region, set the endpoint to "imagesearch-vpc.cn-hangzhou.aliyuncs.com". // Replace the value with the region where you purchased the instance. For example, if you purchased an instance in the China (Hangzhou) region, set regionId to "cn-hangzhou". regionId: "cn-shanghai", protocol: 'http' }); async function demo() { const checkImageExistsRequest = new imagesearch.CheckImageExistsRequest({ // Required. The name of the Image Search instance. Note that this is the instance name, not the instance ID. You can view the instance name in the Instance Information section of the Image Search console at https://imagesearch.console.aliyun.com/overview. instanceName: "XXXXXXX", // Required. The product ID. The ID can be up to 256 characters in length. // A product can have multiple images. productId: "123455", // Required. The image name. The name can be up to 256 characters in length. // 1. The combination of ProductId and PicName uniquely identifies an image. picName: "this", }); const checkImageExistsResponse = await client.checkImageExists(checkImageExistsRequest); console.log(2, checkImageExistsResponse); } demo();Response example
checkImageExistsResponse { requestId: '4B039098-B274-41DE-9A55-32550B6F74E1', success: true, code: 0, exists: false, msg: 'success' }