Java SDK

Updated at:

Image Search provides a Java SDK with code examples for each API operation.

Note

For more information about the service and technical support, click Online Consultation or contact us in the 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 filter conditions.

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.

  • Add the SDK to your project

    Add the Image Search SDK dependency to your project using Maven.

      <dependency>
            <groupId>com.aliyun</groupId>
            <artifactId>imagesearch20201214</artifactId>
            <version>4.4.0</version>
       </dependency>

Add API

  • Code example

    import com.aliyun.imagesearch20201214.Client;
    import com.aliyun.imagesearch20201214.models.AddImageAdvanceRequest;
    import com.aliyun.imagesearch20201214.models.AddImageResponse;
    import com.aliyun.teaopenapi.models.Config;
    import com.aliyun.tea.TeaException;
    import com.aliyun.teautil.models.RuntimeOptions;
    import java.net.URL;
    import java.io.FileInputStream;
    import java.io.InputStream;
    public class Add {
        public static void main(String[] args) throws Exception {
            Config authConfig = new Config();
            // Create an AK/SK pair: https://help.aliyun.com/document_detail/116401.htm
            // An Alibaba Cloud account's AccessKey pair has permissions to call all APIs. We recommend that you use a Resource Access Management (RAM) user to call APIs or perform routine O&M.
            // Never store your AccessKey ID and AccessKey secret in your source code. Doing so may expose your credentials and compromise all resources under your account.
            // This example stores the AccessKey ID and AccessKey secret in environment variables. You can also store them in a configuration file as needed.
            authConfig.accessKeyId = System.getenv("CC_AK_ENV");
            authConfig.accessKeySecret = System.getenv("CC_SK_ENV");
            authConfig.type = "access_key";
            authConfig.regionId = "cn-shanghai"; // Replace this value with the region where your instance is deployed. For example, if your instance is deployed in China (Hangzhou), set regionId to "cn-hangzhou".
            authConfig.endpoint = "imagesearch.cn-shanghai.aliyuncs.com"; // Replace this value with the endpoint for your instance's region. For example, if your instance is deployed in China (Hangzhou), set endpoint to "imagesearch.cn-hangzhou.aliyuncs.com".
            
            // The following shows how to access the service over an internal network (VPC).
            // Note: Internal network (VPC) access is available only for ECS instances or other resources in the same region as your image search instance. For example, if your image search instance is deployed in China (Shanghai), your ECS instance or other resources must also be deployed in China (Shanghai) to access the service over the VPC endpoint. Otherwise, the request fails. If you encounter failures, verify that your ECS instance or other resources are in the same region as your image search instance.
            // authConfig.endpointType = "internal";  // Required for internal network (VPC) access. Set this parameter to "internal".
            // authConfig.endpoint = "imagesearch-vpc.cn-shanghai.aliyuncs.com"; // Replace this value with the VPC endpoint for your instance's region. For example, if your instance is deployed in China (Hangzhou), set endpoint to "imagesearch-vpc.cn-hangzhou.aliyuncs.com".
            
            Client client = new Client(authConfig);
            AddImageAdvanceRequest request = new AddImageAdvanceRequest();
            // Required. The instance name of your image search service. Note: This is the instance name, not the instance ID. You can find it in the instance information section of the Alibaba Cloud console.
            request.instanceName = "XXXXXXXXXXX";
            // Required. The product ID. Maximum length: 256 characters.
            // A product can have multiple images.
            request.productId = "test";
            // Required. The image name. Maximum length: 256 characters.
            // 1. ProductId + PicName uniquely identifies an image.
            // 2. If you add multiple images with the same ProductId + PicName, the last addition overwrites previous ones.
            request.picName = "cloth.jpg";
            // Optional. The category ID of the image.
            // 1. For product search: If you specify a category, the system uses it. If you do not specify one, the system predicts the category. You can retrieve the predicted category from the response.
            // 2. For fabric, trademark, and generic image search: The system sets the category to 88888888 regardless of whether you specify one.
            request.categoryId = 3;
            // Optional. Custom content. Maximum length: 4096 characters.
            // The system returns this field in search responses. For example, you can add a description of the image.
            request.customContent = "this is a simple test";
            // Optional. An integer attribute used for filtering during searches. The system returns this field in search responses.
            // For example, assign different IntAttr values to images from different sites or users. Then filter results by IntAttr to isolate them.
            request.intAttr = 56;
            // Optional. A string attribute used for filtering during searches. Maximum length: 128 characters. The system returns this field in search responses.
            request.strAttr = "test";
            // Optional. Specifies whether to perform subject identification. Default: true.
            // 1. If true, the system performs subject identification and searches based on the identified subject. You can retrieve the subject identification result from the response.
            // 2. If false, the system searches the entire image.
            // 3. For fabric image search, this parameter is ignored. The system searches the entire image.
            request.crop = true;
            // Optional. The subject region of the image, formatted as x1,x2,y1,y2, where (x1,y1) is the top-left corner and (x2,y2) is the bottom-right corner. The specified region must not exceed the image boundaries.
            // If you specify a region, the system searches that region regardless of the Crop setting.
            // For fabric image search, this parameter is ignored. The system searches the entire image.
            request.region = "167,467,221,407";
            RuntimeOptions runtimeOptions = new RuntimeOptions();
            String picName = "D:/123.jpg";               
            try {            
                // Image content. Maximum size: 4 MB. Maximum transmission wait time: 5 seconds. Supported formats: PNG, JPG, JPEG, BMP, GIF, WEBP, TIFF, and PPM.
                // For product, trademark, and generic image search: Both width and height must be between 100 and 4096 pixels.
                // For fabric image search: Both width and height must be between 448 and 4096 pixels.
                // Images must not contain rotation information.
    
                // The following commented code shows how to provide an image URL.
                // String url = "https://www.example.com/123.jpg"; 
                // request.picContentObject = new URL(url).openStream();
    
                // The following uploads an image file.
                InputStream inputStream = new FileInputStream(picName);
                request.picContentObject = inputStream;                  
                AddImageResponse response = client.addImageAdvance(request,runtimeOptions);
                System.out.println("success: " + response.getBody().success + ". message: " 
                    + response.getBody().message        + ". categoryId: " 
                    + response.getBody().picInfo.categoryId + ". region:" 
                    + response.getBody().picInfo.region        
                    + ". requestId: " + response.getBody().requestId);
            } catch (TeaException e) {
                System.out.println(e.getCode());
                System.out.println(e.getData());
                System.out.println(e.getMessage());
                e.printStackTrace();
            }
        }
    }
  • Sample response

    success: true. message: success. categoryId: 9. region:383,681,291,549. requestId: 016D63E3-D0C5-42D3-8879-55E1A705FBA4

SearchImageByPic API

  • Code example

    import com.aliyun.imagesearch20201214.Client;
    import com.aliyun.teaopenapi.models.Config;
    import com.aliyun.imagesearch20201214.models.SearchImageByPicAdvanceRequest;
    import com.aliyun.imagesearch20201214.models.SearchImageByPicResponse;
    import com.aliyun.tea.TeaException;
    import com.aliyun.teautil.models.RuntimeOptions;
    import java.io.FileInputStream;
    import java.net.URL;
    import java.io.InputStream;
    import java.util.List;
    public class SearchImageByPic {
        public static void main(String[] args) throws Exception {
            Config authConfig = new Config();
            // Create an AK/SK pair: https://help.aliyun.com/document_detail/116401.htm
            // An Alibaba Cloud account's AccessKey pair has permissions to call all APIs. We recommend that you use a Resource Access Management (RAM) user to call APIs or perform routine O&M.
            // Never store your AccessKey ID and AccessKey secret in your source code. Doing so may expose your credentials and compromise all resources under your account.
            // This example stores the AccessKey ID and AccessKey secret in environment variables. You can also store them in a configuration file as needed.
            authConfig.accessKeyId = System.getenv("CC_AK_ENV");
            authConfig.accessKeySecret = System.getenv("CC_SK_ENV");
            authConfig.type = "access_key";
            authConfig.regionId = "cn-shanghai"; // Replace this value with the region where your instance is deployed. For example, if your instance is deployed in China (Hangzhou), set regionId to "cn-hangzhou".
            authConfig.endpoint = "imagesearch.cn-shanghai.aliyuncs.com"; // Replace this value with the endpoint for your instance's region. For example, if your instance is deployed in China (Hangzhou), set endpoint to "imagesearch.cn-hangzhou.aliyuncs.com".
            
            // The following shows how to access the service over an internal network (VPC).
            // Note: Internal network (VPC) access is available only for ECS instances or other resources in the same region as your image search instance. For example, if your image search instance is deployed in China (Shanghai), your ECS instance or other resources must also be deployed in China (Shanghai) to access the service over the VPC endpoint. Otherwise, the request fails. If you encounter failures, verify that your ECS instance or other resources are in the same region as your image search instance.
            // authConfig.endpointType = "internal";  // Required for internal network (VPC) access. Set this parameter to "internal".
            // authConfig.endpoint = "imagesearch-vpc.cn-shanghai.aliyuncs.com"; // Replace this value with the VPC endpoint for your instance's region. For example, if your instance is deployed in China (Hangzhou), set endpoint to "imagesearch-vpc.cn-hangzhou.aliyuncs.com".
            
    
            Client client = new Client(authConfig);
            SearchImageByPicAdvanceRequest request = new SearchImageByPicAdvanceRequest();
            // Required. The instance name of your image search service. Note: This is the instance name, not the instance ID. You can find it in the instance information section of the Alibaba Cloud console.
            request.instanceName = "XXXXXXXXX";
            // Optional. The product category ID.
            // 1. For product search: If you specify a category, the system uses it. If you do not specify one, the system predicts the category. You can retrieve the predicted category from the response.
            // 2. For fabric, trademark, and generic image search: The system sets the category to 88888888 regardless of whether you specify one.
            request.categoryId = 3;
            // Optional. The number of results to return. Valid values: 1 to 100. Default: 10.
            request.num = 10;
            // Optional. The starting position of the results. Valid values: 0 to 499. Default: 0.
            request.start = 0;
            // Optional. Specifies whether to perform subject identification. Default: true.
            // 1. If true, the system performs subject identification and searches based on the identified subject. You can retrieve the subject identification result from the response.
            // 2. If false, the system searches the entire image.
            // 3. For fabric image search, this parameter is ignored. The system searches the entire image.
            request.crop = true;
            // Optional. The subject region of the image, formatted as x1,x2,y1,y2, where (x1,y1) is the top-left corner and (x2,y2) is the bottom-right corner. The specified region must not exceed the image boundaries.
            // If you specify a region, the system searches that region regardless of the Crop setting.
            // 3. For fabric image search, this parameter is ignored. The system searches the entire image.
            request.region="167,467,221,407";
            // Optional. Filter conditions.
            // Operators supported for int_attr: in, not in, >, >=, <, <=, =. Operators supported for str_attr: in, not in, =, !=. Combine multiple conditions with AND or OR.
            // Examples:
            //  1. Filter by IntAttr: int_attr>=100
            //  2. Filter by StrAttr: str_attr!="value1"
            //  3. Filter by IntAttr and StrAttr: int_attr=1000 AND str_attr="value1"
            request.filter="int_attr=56 AND str_attr=\"test\" AND int_attr2 in (56)";
            // Optional. Similarity score threshold.
            // Only images with a similarity score greater than or equal to this threshold are returned. Valid range: 0.00 to 1.00. Up to two decimal places are supported. Default: 0.00.
            request.scoreThreshold="0.54";
            String picName = "D:/123.jpg";
            // Image content. Maximum size: 4 MB. Maximum transmission wait time: 5 seconds. Supported formats: PNG, JPG, JPEG, BMP, GIF, WEBP, TIFF, and PPM.
            // For product, trademark, and generic image search: Both width and height must be between 100 and 4096 pixels.
            // For fabric image search: Both width and height must be between 448 and 4096 pixels.
            // Images must not contain rotation information.
            request.num = 10;
            request.start = 0;
            // Optional. If true, the response groups results by ProductId.
            request.distinctProductId=false;
            RuntimeOptions runtimeObject =  new RuntimeOptions();
            try {
                // The following commented code shows how to provide an image URL.
                // String url = "https://www.example.com/123.jpg"; 
                // request.picContentObject = new URL(url).openStream();  
     
                // The following uploads an image file.         
                InputStream inputStream = new FileInputStream(picName);
                request.picContentObject = inputStream; 
                SearchImageByPicResponse response = client.searchImageByPicAdvance(request, runtimeObject);
                System.out.println(response.getBody().requestId);
                System.out.println(response.getBody().picInfo.categoryId);
                System.out.println(response.getBody().picInfo.region);
                List<SearchImageByPicResponseBody.SearchImageByPicResponseBodyAuctions> auctions = response.getBody().getAuctions();
                for(SearchImageByPicResponseBody.SearchImageByPicResponseBodyAuctions auction:auctions) {    
                    System.out.println(auction.categoryId + " " + auction.picName + " " 
                        + auction.productId + " " + auction.customContent + " " + auction.score + " " 
                        + auction.strAttr + " " + auction.intAttr);
                }
                System.out.println("Multi-subject information");
                SearchImageByPicResponseBody.SearchImageByPicResponseBodyPicInfo picInfo = response.getBody().getPicInfo();
                for (SearchImageByPicResponseBody.SearchImageByPicResponseBodyPicInfoMultiRegion multiRegion : picInfo.getMultiRegion()) {    
                    System.out.println(multiRegion.region);
                }
            } catch (TeaException e) {
                System.out.println(e.getCode());
                System.out.println(e.getData());
                System.out.println(e.getMessage());
                e.printStackTrace();
            }
        }
    }
  • Sample response

    09BE019A-AE3D-4D22-99C9-10533D8AC631
    3
    167,467,221,407
    3 1000 test this is a simple test 1.0 test 56
    Multi-subject information
    112,440,76,387

SearchImageByName API

  • Code example

    import com.aliyun.imagesearch20201214.Client;
    import com.aliyun.teaopenapi.models.Config;
    import com.aliyun.imagesearch20201214.models.SearchImageByNameRequest;
    import com.aliyun.imagesearch20201214.models.SearchImageByNameResponse;
    import com.aliyun.tea.TeaException;
    import java.util.List;
    public class  SearchImageByName{
        public static void main(String[] args) throws Exception {
            
            Config authConfig = new Config();
            // Create an AK/SK pair: https://help.aliyun.com/document_detail/116401.html
            // An Alibaba Cloud account's AccessKey pair has permissions to call all APIs. We recommend that you use a Resource Access Management (RAM) user to call APIs or perform routine O&M.
            // Never store your AccessKey ID and AccessKey secret in your source code. Doing so may expose your credentials and compromise all resources under your account.
            // This example stores the AccessKey ID and AccessKey secret in environment variables. You can also store them in a configuration file as needed.
            authConfig.accessKeyId = System.getenv("CC_AK_ENV");
            authConfig.accessKeySecret = System.getenv("CC_SK_ENV");
            authConfig.type = "access_key";
            authConfig.regionId = "cn-shanghai"; // Replace this value with the region where your instance is deployed. For example, if your instance is deployed in China (Hangzhou), set regionId to "cn-hangzhou".
            authConfig.endpoint = "imagesearch.cn-shanghai.aliyuncs.com"; // Replace this value with the endpoint for your instance's region. For example, if your instance is deployed in China (Hangzhou), set endpoint to "imagesearch.cn-hangzhou.aliyuncs.com".
            
            // The following shows how to access the service over an internal network (VPC).
            // Note: Internal network (VPC) access is available only for ECS instances or other resources in the same region as your image search instance. For example, if your image search instance is deployed in China (Shanghai), your ECS instance or other resources must also be deployed in China (Shanghai) to access the service over the VPC endpoint. Otherwise, the request fails. If you encounter failures, verify that your ECS instance or other resources are in the same region as your image search instance.
            // authConfig.endpointType = "internal";  // Required for internal network (VPC) access. Set this parameter to "internal".
            // authConfig.endpoint = "imagesearch-vpc.cn-shanghai.aliyuncs.com"; // Replace this value with the VPC endpoint for your instance's region. For example, if your instance is deployed in China (Hangzhou), set endpoint to "imagesearch-vpc.cn-hangzhou.aliyuncs.com".
            
    
            Client client = new Client(authConfig);
            SearchImageByNameRequest request = new SearchImageByNameRequest();
            // Required. The instance name of your image search service. Note: This is the instance name, not the instance ID. You can find it in the instance information section of the Alibaba Cloud console.
            request.instanceName = "XXXXXXXXX";
            // Required. The product ID. Maximum length: 256 characters.
            // A product can have multiple images.
            request.productId = "test";
            // Required. The image name. Maximum length: 256 characters.
            // ProductId + PicName uniquely identifies an image.
            request.picName = "1000";
            // Optional. The product category ID.
            // 1. For product search: If you specify a category, the system uses it. If you do not specify one, the system predicts the category. You can retrieve the predicted category from the response.
            // 2. For fabric, trademark, and generic image search: The system sets the category to 88888888 regardless of whether you specify one.
            request.categoryId = 3;
            // Optional. The number of results to return. Valid values: 1 to 100. Default: 10.
            request.num =10;
            // Optional. The starting position of the results. Valid values: 0 to 499. Default: 0.
            request.start =0;
            // Optional. Filter conditions.
            // Operators supported for int_attr: in, not in, >, >=, <, <=, =. Operators supported for str_attr: in, not in, =, !=. Combine multiple conditions with AND or OR.
            // Examples:
            //  1. Filter by IntAttr: int_attr>=100
            //  2. Filter by StrAttr: str_attr!="value1"
            //  3. Filter by IntAttr and StrAttr: int_attr=1000 AND str_attr="value1"
            request.filter="int_attr=56 AND str_attr=\"test\" AND int_attr2 in (56)";
            // Optional. Similarity score threshold.
            // Only images with a similarity score greater than or equal to this threshold are returned. Valid range: 0.00 to 1.00. Up to two decimal places are supported. Default: 0.00.
            request.scoreThreshold="0.54";
            try {
                SearchImageByNameResponse response = client.searchImageByName(request);
                System.out.println(response.getBody().requestId);
                System.out.println(response.getBody().picInfo.categoryId);
                System.out.println(response.getBody().picInfo.region);
                List<SearchImageByNameResponseBody.SearchImageByNameResponseBodyAuctions> auctions = response.getBody().getAuctions();
                for(SearchImageByNameResponseBody.SearchImageByNameResponseBodyAuctions auction:auctions) {    
                    System.out.println(auction.categoryId + " " + auction.picName + " " 
                        + auction.productId + " " + auction.customContent + " " + auction.score + " " 
                        + auction.strAttr + " " + auction.intAttr);
                }
            } catch (TeaException e) {
                System.out.println(e.getCode());
                System.out.println(e.getData());
                System.out.println(e.getMessage());
                e.printStackTrace();
            }
        }
    }
  • Sample response

    8F2441C8-EA05-461B-A4AC-5F5DE25FAC21
    3
    null
    3 1000 test this is a simple test 1.0 test 56
                        

SearchImageByText API

Important

The SearchImageByText API is available only for product multimodal search.

  • Code example

    import com.aliyun.imagesearch20201214.Client;
    import com.aliyun.teaopenapi.models.Config;
    import com.aliyun.imagesearch20201214.models.*;
    import com.aliyun.tea.TeaException;
    import java.util.List;
    public class SearchImageByText {
        public static void main(String[] args) throws Exception {
            Config authConfig = new Config();
            // Create an AK/SK pair: https://help.aliyun.com/document_detail/116401.htm
            // An Alibaba Cloud account's AccessKey pair has permissions to call all APIs. We recommend that you use a Resource Access Management (RAM) user to call APIs or perform routine O&M.
            // Never store your AccessKey ID and AccessKey secret in your source code. Doing so may expose your credentials and compromise all resources under your account.
            // This example stores the AccessKey ID and AccessKey secret in environment variables. You can also store them in a configuration file as needed.
            authConfig.accessKeyId = System.getenv("CC_AK_ENV");
            authConfig.accessKeySecret = System.getenv("CC_SK_ENV");
            authConfig.type = "access_key";
            authConfig.regionId = "cn-shanghai"; // Replace this value with the region where your instance is deployed. For example, if your instance is deployed in China (Hangzhou), set regionId to "cn-hangzhou".
            authConfig.endpoint = "imagesearch.cn-shanghai.aliyuncs.com"; // Replace this value with the endpoint for your instance's region. For example, if your instance is deployed in China (Hangzhou), set endpoint to "imagesearch.cn-hangzhou.aliyuncs.com".
            
            // The following shows how to access the service over an internal network (VPC).
            // Note: Internal network (VPC) access is available only for ECS instances or other resources in the same region as your image search instance. For example, if your image search instance is deployed in China (Shanghai), your ECS instance or other resources must also be deployed in China (Shanghai) to access the service over the VPC endpoint. Otherwise, the request fails. If you encounter failures, verify that your ECS instance or other resources are in the same region as your image search instance.
            // authConfig.endpointType = "internal";  // Required for internal network (VPC) access. Set this parameter to "internal".
            // authConfig.endpoint = "imagesearch-vpc.cn-shanghai.aliyuncs.com"; // Replace this value with the VPC endpoint for your instance's region. For example, if your instance is deployed in China (Hangzhou), set endpoint to "imagesearch-vpc.cn-hangzhou.aliyuncs.com".
            
    
            Client client = new Client(authConfig);
            SearchImageByTextRequest request = new SearchImageByTextRequest();
            // Required. The instance name of your image search service. Note: This is the instance name, not the instance ID. You can find it in the instance information section of the Alibaba Cloud console.
            // Note: This API is available only for product multimodal search.
            request.instanceName = "XXXXXXXXX";
            // Optional. The number of results to return. Valid values: 1 to 100. Default: 10.
            request.num = 10;
            // Optional. The starting position of the results. Valid values: 0 to 499. Default: 0.
            request.start = 0;
            // Optional. Filter conditions.
            // Operators supported for int_attr: in, not in, >, >=, <, <=, =. Operators supported for str_attr: in, not in, =, !=. Combine multiple conditions with AND or OR.
            // Examples:
            //  1. Filter by IntAttr: int_attr>=100
            //  2. Filter by StrAttr: str_attr!="value1"
            //  3. Filter by IntAttr and StrAttr: int_attr=1000 AND str_attr="value1"
            request.filter="int_attr=56 AND str_attr=\"test\" AND int_attr2 in (56)";
            // Optional. Similarity score threshold.
            // Only images with a similarity score greater than or equal to this threshold are returned. Valid range: 0.00 to 1.00. Up to two decimal places are supported. Default: 0.00.
            request.scoreThreshold="0.54";
            // Text description. Supports Chinese and English. Maximum length: 512 characters.
            request.text = "xxxx";
            request.num = 10;
            request.start = 0;
            // Optional. If true, the response groups results by ProductId.
            request.distinctProductId=false;
            try {
                SearchImageByTextResponse response = client.searchImageByText(request);
                System.out.println(response.getBody().requestId);
                List<SearchImageByTextResponseBody.SearchImageByTextResponseBodyAuctions> auctions = response.getBody().getAuctions();
                for(SearchImageByTextResponseBody.SearchImageByTextResponseBodyAuctions auction:auctions) {
                    System.out.println(auction.categoryId + " " + auction.picName + " "
                            + auction.productId + " " + auction.customContent + " " + auction.score + " "
                            + auction.strAttr + " " + auction.intAttr);
                }
            } catch (TeaException e) {
                System.out.println(e.getCode());
                System.out.println(e.getData());
                System.out.println(e.getMessage());
                e.printStackTrace();
            }
        }
    }
  • Sample response

    09BE019A-AE3D-4D22-99C9-10533D8AC631
    3 1000 test this is a simple test 1.0 test 56

SearchImageByFilter API

  • Code example

    import com.aliyun.imagesearch20201214.Client;
    import com.aliyun.teaopenapi.models.Config;
    import com.aliyun.imagesearch20201214.models.*;
    import com.aliyun.tea.TeaException;
    import java.util.List;
    public class SearchImageByFilter {
        public static void main(String[] args) throws Exception {
            Config authConfig = new Config();
            // To create an access key, see https://help.aliyun.com/document_detail/116401.htm.
            // The access key of an Alibaba Cloud account grants full access to all API operations. We recommend that you use a RAM user to call API operations or perform routine O&M.
            // For security, avoid hardcoding your AccessKey ID and AccessKey Secret in your code. Hardcoding your credentials can lead to access key leaks, compromising all resources under your account.
            // This example stores the AccessKey ID and AccessKey Secret in environment variables. You can also store them in a configuration file.
            authConfig.accessKeyId = System.getenv("CC_AK_ENV");
            authConfig.accessKeySecret = System.getenv("CC_SK_ENV");
            authConfig.type = "access_key";
            authConfig.regionId = "cn-shanghai"; // Replace this with the ID of the region where your instance is deployed. For example, use "cn-hangzhou" for the China (Hangzhou) region.
            authConfig.endpoint = "imagesearch.cn-shanghai.aliyuncs.com"; // Replace this with the endpoint for your instance's region. For example, use "imagesearch.cn-hangzhou.aliyuncs.com" for the China (Hangzhou) region.
            
            // To use an internal access (VPC) endpoint:
            // Note: For internal access, your resource (such as an ECS instance) and your Image Search instance must be in the same region. Otherwise, the API call will fail.
            // authConfig.endpointType = "internal";  // Set to "internal" for internal access.
            // authConfig.endpoint = "imagesearch-vpc.cn-shanghai.aliyuncs.com"; // The VPC endpoint. Replace this with the VPC endpoint for your instance's region. For example, use "imagesearch-vpc.cn-hangzhou.aliyuncs.com" for the China (Hangzhou) region.
            
    
            Client client = new Client(authConfig);
            SearchImageByFilterRequest request = new SearchImageByFilterRequest();
            // Required. The name of the Image Search instance. Note: This is the instance name, not the instance ID. You can view the instance name in the console after deployment.
            request.instanceName = "XXXXXXXXX";
            // Optional. The number of results to return. Valid values: 1 to 100. Default: 10.
            request.num = 10;
            // Optional. The starting position of the results. Valid values: 0 to 499. Default: 0.
            request.start = 0;
            // Required. The filter condition.
            // Operators supported for int_attr: in, not in, >, >=, <, <=, =. Operators supported for str_attr: in, not in, =, !=. Combine multiple conditions with AND or OR.
            // Examples:
            //  1. Filter by IntAttr: int_attr>=100
            //  2. Filter by StrAttr: str_attr!="value1"
            //  3. Filter by IntAttr and StrAttr: int_attr=1000 AND str_attr="value1"
            request.filter="int_attr=56 AND str_attr=\"test\" AND int_attr2 in (56)";
            
            try {
                SearchImageByFilterResponse response = client.searchImageByFilter(request);
                System.out.println(response.getBody().requestId);
                List<SearchImageByFilterResponse.SearchImageByFilterResponseBodyAuctions> auctions = response.getBody().getAuctions();
                for(SearchImageByFilterResponseBody.SearchImageByFilterResponseBodyAuctions auction:auctions) {
                    System.out.println(auction.categoryId + " " + auction.picName + " "
                            + auction.productId + " " + auction.customContent + " "
                            + auction.strAttr + " " + auction.intAttr);
                }
            } catch (TeaException e) {
                System.out.println(e.getCode());
                System.out.println(e.getData());
                System.out.println(e.getMessage());
                e.printStackTrace();
            }
        }
    }
  • Sample response

    09BE019A-AE3D-4D22-99C9-10533D8AC631
    3 1000 test this is a simple test  test 56

Delete API

  • Code example

    import com.aliyun.imagesearch20201214.Client;
    import com.aliyun.teaopenapi.models.Config;
    import com.aliyun.imagesearch20201214.models.DeleteImageRequest;
    import com.aliyun.imagesearch20201214.models.DeleteImageResponse;
    import com.aliyun.tea.TeaException;
    public class Delete {
        public static void main(String[] args) throws Exception {
            Config authConfig = new Config();
            // For information about how to create an AccessKey pair, see https://www.alibabacloud.com/help/en/ram/user-guide/create-an-accesskey-pair.
            // An Alibaba Cloud account's AccessKey pair has permissions to call all API operations. We recommend that you use a RAM user to call API operations or perform routine O&M.
            // Never store your AccessKey ID and AccessKey Secret in your source code. Doing so may expose your credentials and compromise all resources under your account.
            // This example stores the AccessKey ID and AccessKey Secret in an environment variable. You can also store them in a configuration file as needed.
            authConfig.accessKeyId = System.getenv("CC_AK_ENV");
            authConfig.accessKeySecret = System.getenv("CC_SK_ENV");
            authConfig.type = "access_key";
            authConfig.regionId = "cn-shanghai"; // Replace this value with the region where your instance is deployed. For example, if your instance is deployed in the China (Hangzhou) region, set regionId to "cn-hangzhou".
            authConfig.endpoint = "imagesearch.cn-shanghai.aliyuncs.com"; // Replace this value with the endpoint for your instance's region. For example, if your instance is deployed in the China (Hangzhou) region, set the endpoint to "imagesearch.cn-hangzhou.aliyuncs.com".
            
            // The following code shows how to access Image Search over an internal network (VPC).
            // Note: To access Image Search over an internal network (VPC), the calling resource (such as an ECS instance) must be in the same region as your Image Search instance. For example, if your instance is in the China (Shanghai) region, the calling resource must also be in the China (Shanghai) region. Otherwise, the request fails. If a request fails, verify that both the resource and the instance are in the same region.
            // authConfig.endpointType = "internal";  // Required. Set to "internal" for internal network (VPC) access.
            // authConfig.endpoint = "imagesearch-vpc.cn-shanghai.aliyuncs.com"; // Replace this value with the VPC endpoint for your instance's region. For example, if your instance is deployed in the China (Hangzhou) region, set the endpoint to "imagesearch-vpc.cn-hangzhou.aliyuncs.com".
            
    
            Client client = new Client(authConfig);
            DeleteImageRequest request = new DeleteImageRequest();
            // 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 Alibaba Cloud console.
            request.instanceName = "XXXXXXXXXXXX";
            // Required if isDeleteByFilter is set to false. The product ID can be up to 256 characters long.
            // A product can have multiple images. If you specify only this parameter and omit picName, the service deletes all images for the specified product and returns their names in the response.
            request.productId = "test";
            // Optional. The image name. If you omit this parameter, the service deletes all images associated with the specified productId. If you specify this parameter, the service deletes only the image identified by the combination of productId and picName.
            request.picName = "1000";
            // Optional. If set to true, the service deletes images based on the filter condition or a combination of the filter condition and the product ID.
            request.isDeleteByFilter = false;
            request.filter = "intattr3=xxx";
            try {
                DeleteImageResponse response = client.deleteImage(request);
                System.out.println(response.getBody().toMap());
            } catch (TeaException e) {
                System.out.println(e.getCode());
                System.out.println(e.getData());
                System.out.println(e.getMessage());
                e.printStackTrace();
            }
        }
    }
  • Sample response

    {
      Message=success,
      RequestId=994A7095-09AA-127A-873B-A2279261605F,
      Data={
        PicNames=[
          82.png
        ]
      },
      Code=0,
      Success=true
    }

UpdateImage API

  • Code example

    import com.aliyun.imagesearch20201214.Client;
    import com.aliyun.teaopenapi.models.Config;
    import com.aliyun.imagesearch20201214.models.*;
    import com.aliyun.tea.TeaException;
    import com.aliyun.teautil.models.RuntimeOptions;
    import java.io.FileInputStream;
    import java.io.InputStream;
    import java.util.List;
    public class UpdateImage {
        public static void main(String[] args) throws Exception {
            Config authConfig = new Config();
            // For information about how to create an AccessKey pair, see https://help.aliyun.com/document_detail/116401.htm.
            // The AccessKey for an Alibaba Cloud account can call all APIs. We recommend using a RAM user for API calls and routine O&M.
            // Never store your AccessKey ID and AccessKey Secret in your source code. Doing so may expose your credentials and compromise all resources under your account.
            // This example stores the AccessKey ID and AccessKey Secret in environment variables. You can also store them in a configuration file.
            authConfig.accessKeyId = System.getenv("CC_AK_ENV");
            authConfig.accessKeySecret = System.getenv("CC_SK_ENV");
            authConfig.type = "access_key";
            authConfig.regionId = "cn-shanghai"; // The region of your Image Search instance. For example, "cn-hangzhou" for the China (Hangzhou) region.
            authConfig.endpoint = "imagesearch.cn-shanghai.aliyuncs.com"; // The endpoint for the instance's region. For example, "imagesearch.cn-hangzhou.aliyuncs.com" for the China (Hangzhou) region.
            
            // The following code shows how to access Image Search over an internal network (VPC).
            // Note: For internal network (VPC) access, the client (such as an ECS instance) and the Image Search instance must be in the same region. Otherwise, requests will fail.
            // authConfig.endpointType = "internal";  // Set to "internal" for internal network (VPC) access.
            // authConfig.endpoint = "imagesearch-vpc.cn-shanghai.aliyuncs.com"; // The VPC endpoint for the instance's region. For example, "imagesearch-vpc.cn-hangzhou.aliyuncs.com" for the China (Hangzhou) region.
            
    
            Client client = new Client(authConfig);
            UpdateImageRequest request = new UpdateImageRequest();
            // Required. The name of the Image Search instance, not the instance ID. You can find the instance name in the instance information section of the Alibaba Cloud console.
            request.instanceName = "XXXXXXXXX";
            // Required. The ID of the product to which the image belongs. This ID cannot be changed.
            request.setProductId("1");
            // Optional. The name of the image. If omitted, this operation updates all images that match the other specified filters.
            request.setPicName("1");
            // Optional. An integer attribute for filtering. This attribute is included in search results.
            request.setIntAttr(1);
            // Optional. A string attribute for filtering, up to 128 characters in length. This attribute is included in search results.
            request.setStrAttr("test");
            // Optional. Custom content, up to 4,096 characters in length.
            request.setCustomContent("This is a test description.");
            UpdateImageResponse response = client.updateImage(request);
            System.out.println("requestId: " + response.getBody().requestId + ". success: " + response.getBody().success + ". message: " + response.getBody().message);     
        }
    }
  • Sample response

    requestId: AB8AA177-89AB-14D5-BEE0-293C32D5C43A. success: true. message: null

Detail API

  • Code example

    import com.aliyun.imagesearch20201214.Client;
    import com.aliyun.teaopenapi.models.Config;
    import com.aliyun.imagesearch20201214.models.*;
    import com.aliyun.tea.TeaException;
    import com.aliyun.teautil.models.RuntimeOptions;
    import java.io.FileInputStream;
    import java.io.InputStream;
    import java.util.List;
    public class Detail {
        public static void main(String[] args) throws Exception {
            Config authConfig = new Config();
            // Create an AK/SK pair: https://help.aliyun.com/document_detail/116401.htm
            // An Alibaba Cloud account's AccessKey pair has permissions to call all APIs. We recommend that you use a Resource Access Management (RAM) user to call APIs or perform routine O&M.
            // Never store your AccessKey ID and AccessKey secret in your source code. Doing so may expose your credentials and compromise all resources under your account.
            // This example stores the AccessKey ID and AccessKey secret in environment variables. You can also store them in a configuration file as needed.
            authConfig.accessKeyId = System.getenv("CC_AK_ENV");
            authConfig.accessKeySecret = System.getenv("CC_SK_ENV");
            authConfig.type = "access_key";
            authConfig.regionId = "cn-shanghai"; // Replace this value with the region where your instance is deployed. For example, if your instance is deployed in China (Hangzhou), set regionId to "cn-hangzhou".
            authConfig.endpoint = "imagesearch.cn-shanghai.aliyuncs.com"; // Replace this value with the endpoint for your instance's region. For example, if your instance is deployed in China (Hangzhou), set endpoint to "imagesearch.cn-hangzhou.aliyuncs.com".
            
            // The following shows how to access the service over an internal network (VPC).
            // Note: Internal network (VPC) access is available only for ECS instances or other resources in the same region as your image search instance. For example, if your image search instance is deployed in China (Shanghai), your ECS instance or other resources must also be deployed in China (Shanghai) to access the service over the VPC endpoint. Otherwise, the request fails. If you encounter failures, verify that your ECS instance or other resources are in the same region as your image search instance.
            // authConfig.endpointType = "internal";  // Required for internal network (VPC) access. Set this parameter to "internal".
            // authConfig.endpoint = "imagesearch-vpc.cn-shanghai.aliyuncs.com"; // Replace this value with the VPC endpoint for your instance's region. For example, if your instance is deployed in China (Hangzhou), set endpoint to "imagesearch-vpc.cn-hangzhou.aliyuncs.com".
            
    
            Client client = new Client(authConfig);
            DetailRequest request = new DetailRequest();
            // Required. The instance name of your image search service. Note: This is the instance name, not the instance ID. You can find it in the instance information section of the Alibaba Cloud console.
            request.instanceName = "XXXXXXXXX";
            DetailResponse detail = client.detail(request);
            System.out.println(detail.getBody().toMap());  
        }
    }
  • Sample response

    {
      RequestId=046913C5-942A-1DD2-959F-7CECD790ADB2,
      Instance={
        UtcExpireTime=1649692800000,
        TotalCount=225320,
        UtcCreate=1633936585000,
        Capacity=250,
        Qps=5,
        ServiceType=0,
        Region=cn-shanghai,
        Name=xxxx
      },
      Success=true
    }

DumpMeta API

  • Code example

    import com.aliyun.imagesearch20201214.Client;
    import com.aliyun.teaopenapi.models.Config;
    import com.aliyun.imagesearch20201214.models.*;
    import com.aliyun.tea.TeaException;
    import com.aliyun.teautil.models.RuntimeOptions;
    import java.io.FileInputStream;
    import java.io.InputStream;
    import java.util.List;
    public class DumpMeta {
        public static void main(String[] args) throws Exception {
            Config authConfig = new Config();
            // Create an AK/SK pair: https://help.aliyun.com/document_detail/116401.htm
            // An Alibaba Cloud account's AccessKey pair has permissions to call all APIs. We recommend that you use a Resource Access Management (RAM) user to call APIs or perform routine O&M.
            // Never store your AccessKey ID and AccessKey secret in your source code. Doing so may expose your credentials and compromise all resources under your account.
            // This example stores the AccessKey ID and AccessKey secret in environment variables. You can also store them in a configuration file as needed.
            authConfig.accessKeyId = System.getenv("CC_AK_ENV");
            authConfig.accessKeySecret = System.getenv("CC_SK_ENV");
            authConfig.type = "access_key";
            authConfig.regionId = "cn-shanghai"; // Replace this value with the region where your instance is deployed. For example, if your instance is deployed in China (Hangzhou), set regionId to "cn-hangzhou".
            authConfig.endpoint = "imagesearch.cn-shanghai.aliyuncs.com"; // Replace this value with the endpoint for your instance's region. For example, if your instance is deployed in China (Hangzhou), set endpoint to "imagesearch.cn-hangzhou.aliyuncs.com".
            
            // The following shows how to access the service over an internal network (VPC).
            // Note: Internal network (VPC) access is available only for ECS instances or other resources in the same region as your image search instance. For example, if your image search instance is deployed in China (Shanghai), your ECS instance or other resources must also be deployed in China (Shanghai) to access the service over the VPC endpoint. Otherwise, the request fails. If you encounter failures, verify that your ECS instance or other resources are in the same region as your image search instance.
            // authConfig.endpointType = "internal";  // Required for internal network (VPC) access. Set this parameter to "internal".
            // authConfig.endpoint = "imagesearch-vpc.cn-shanghai.aliyuncs.com"; // Replace this value with the VPC endpoint for your instance's region. For example, if your instance is deployed in China (Hangzhou), set endpoint to "imagesearch-vpc.cn-hangzhou.aliyuncs.com".
            
    
            Client client = new Client(authConfig);
            DumpMetaRequest request = new DumpMetaRequest();
            // Required. The instance name of your image search service. Note: This is the instance name, not the instance ID. You can find it in the instance information section of the Alibaba Cloud console.
            request.instanceName = "XXXXXXXXX";
            DumpMetaResponse response = client.dumpMeta(request);
            System.out.println(response.getBody().toMap());  
        }
    }
  • Sample response

    {
      RequestId=FC4191AA-1D5B-1001-9A70-18FBB2BD265B,
      Data={
        DumpMetaStatus=PROCESSING,
        Id=567
      },
      Success=true
    }

DumpMetaList API

  • Code example

    import com.aliyun.imagesearch20201214.Client;
    import com.aliyun.teaopenapi.models.Config;
    import com.aliyun.imagesearch20201214.models.*;
    import com.aliyun.tea.TeaException;
    import com.aliyun.teautil.models.RuntimeOptions;
    import java.io.FileInputStream;
    import java.io.InputStream;
    import java.util.List;
    public class DumpMetaList {
        public static void main(String[] args) throws Exception {
            Config authConfig = new Config();
            // Create an AK/SK pair: https://help.aliyun.com/document_detail/116401.htm
            // An Alibaba Cloud account's AccessKey pair has permissions to call all APIs. We recommend that you use a Resource Access Management (RAM) user to call APIs or perform routine O&M.
            // Never store your AccessKey ID and AccessKey secret in your source code. Doing so may expose your credentials and compromise all resources under your account.
            // This example stores the AccessKey ID and AccessKey secret in environment variables. You can also store them in a configuration file as needed.
            authConfig.accessKeyId = System.getenv("CC_AK_ENV");
            authConfig.accessKeySecret = System.getenv("CC_SK_ENV");
            authConfig.type = "access_key";
            authConfig.regionId = "cn-shanghai"; // Replace this value with the region where your instance is deployed. For example, if your instance is deployed in China (Hangzhou), set regionId to "cn-hangzhou".
            authConfig.endpoint = "imagesearch.cn-shanghai.aliyuncs.com"; // Replace this value with the endpoint for your instance's region. For example, if your instance is deployed in China (Hangzhou), set endpoint to "imagesearch.cn-hangzhou.aliyuncs.com".
            
            // The following shows how to access the service over an internal network (VPC).
            // Note: Internal network (VPC) access is available only for ECS instances or other resources in the same region as your image search instance. For example, if your image search instance is deployed in China (Shanghai), your ECS instance or other resources must also be deployed in China (Shanghai) to access the service over the VPC endpoint. Otherwise, the request fails. If you encounter failures, verify that your ECS instance or other resources are in the same region as your image search instance.
            // authConfig.endpointType = "internal";  // Required for internal network (VPC) access. Set this parameter to "internal".
            // authConfig.endpoint = "imagesearch-vpc.cn-shanghai.aliyuncs.com"; // Replace this value with the VPC endpoint for your instance's region. For example, if your instance is deployed in China (Hangzhou), set endpoint to "imagesearch-vpc.cn-hangzhou.aliyuncs.com".
            
    
            Client client = new Client(authConfig);
            DumpMetaListRequest request = new DumpMetaListRequest();
            // Required. The instance name of your image search service. Note: This is the instance name, not the instance ID. You can find it in the instance information section of the Alibaba Cloud console.
            request.instanceName = "XXXXXXXXX";
            // Optional. The metadata export task ID.
            request.setId(567L);
            // Optional. The starting page number. Default: 1.
            request.setPageNumber(1);
            // Optional. The number of entries per page. Default: 20.
            request.setPageSize(1);
            DumpMetaListResponse response = client.dumpMetaList(request);
            System.out.println(response.getBody().toMap()); 
        }
    }
  • Sample response

    {
      RequestId=850DFBD9-A179-12FB-B193-2D08ACEA586B,
      Data={
        TotalCount=1,
        PageSize=1,
        PageNumber=1,
        DumpMetaList=[
          {
            Status=SUCCESS,
            Msg=success,
            MetaUrl=https://example.com/x?Expires=x,
            UtcCreate=1639969113000,
            UtcModified=1639969140000,
            Id=567,
            Code=0
          }
        ]
      }
    }

BatchTask API

  • Code example

    import com.aliyun.imagesearch20201214.Client;
    import com.aliyun.teaopenapi.models.Config;
    import com.aliyun.imagesearch20201214.models.*;
    import com.aliyun.tea.TeaException;
    import com.aliyun.teautil.models.RuntimeOptions;
    import java.io.FileInputStream;
    import java.io.InputStream;
    import java.util.List;
    public class BatchTask {
        public static void main(String[] args) throws Exception {
            Config authConfig = new Config();
            // Create an AK/SK pair: https://help.aliyun.com/document_detail/116401.htm
            // An Alibaba Cloud account's AccessKey pair has permissions to call all APIs. We recommend that you use a Resource Access Management (RAM) user to call APIs or perform routine O&M.
            // Never store your AccessKey ID and AccessKey secret in your source code. Doing so may expose your credentials and compromise all resources under your account.
            // This example stores the AccessKey ID and AccessKey secret in environment variables. You can also store them in a configuration file as needed.
            authConfig.accessKeyId = System.getenv("CC_AK_ENV");
            authConfig.accessKeySecret = System.getenv("CC_SK_ENV");
            authConfig.type = "access_key";
            authConfig.regionId = "cn-shanghai"; // Replace this value with the region where your instance is deployed. For example, if your instance is deployed in China (Hangzhou), set regionId to "cn-hangzhou".
            authConfig.endpoint = "imagesearch.cn-shanghai.aliyuncs.com"; // Replace this value with the endpoint for your instance's region. For example, if your instance is deployed in China (Hangzhou), set endpoint to "imagesearch.cn-hangzhou.aliyuncs.com".
            
            // The following shows how to access the service over an internal network (VPC).
            // Note: Internal network (VPC) access is available only for ECS instances or other resources in the same region as your image search instance. For example, if your image search instance is deployed in China (Shanghai), your ECS instance or other resources must also be deployed in China (Shanghai) to access the service over the VPC endpoint. Otherwise, the request fails. If you encounter failures, verify that your ECS instance or other resources are in the same region as your image search instance.
            // authConfig.endpointType = "internal";  // Required for internal network (VPC) access. Set this parameter to "internal".
            // authConfig.endpoint = "imagesearch-vpc.cn-shanghai.aliyuncs.com"; // Replace this value with the VPC endpoint for your instance's region. For example, if your instance is deployed in China (Hangzhou), set endpoint to "imagesearch-vpc.cn-hangzhou.aliyuncs.com".
            
    
            Client client = new Client(authConfig);
            IncreaseInstanceRequest request = new IncreaseInstanceRequest();
            // Required. The instance name of your image search service. Note: This is the instance name, not the instance ID. You can find it in the instance information section of the Alibaba Cloud console.
            request.instanceName = "XXXXXXXXX";
            // Required. The OSS bucket name.
            request.setBucketName("bucketName");
            // Required. The path. Must start with / and must not end with /.
            // Prepare the increment.meta file in this path in advance. For more information, see the Batch Operations section in the User Guide.
            request.setPath("/public/xxx");
            // Optional. The callback address for successful requests. Format: http(s)://.
            request.setCallbackAddress("http://xxx/xxx");
            IncreaseInstanceResponse response = client.increaseInstance(request);
            System.out.println(response.getBody().toMap()); 
        }
    }
  • Sample response

    {
      RequestId=F9BAD635-3031-1EBB-BE9E-E9FCB318A28C,
      Data={
        IncrementStatus=PROCESSING,
        Id=1470
      },
      Success=true
    }
                        

BatchTaskList API

  • Code example

    import com.aliyun.imagesearch20201214.Client;
    import com.aliyun.teaopenapi.models.Config;
    import com.aliyun.imagesearch20201214.models.*;
    import com.aliyun.tea.TeaException;
    import com.aliyun.teautil.models.RuntimeOptions;
    import java.io.FileInputStream;
    import java.io.InputStream;
    import java.util.List;
    public class BatchTaskList {
        public static void main(String[] args) throws Exception {
            Config authConfig = new Config();
            // Create an AK/SK pair: https://help.aliyun.com/document_detail/116401.htm
            // An Alibaba Cloud account's AccessKey pair has permissions to call all APIs. We recommend that you use a Resource Access Management (RAM) user to call APIs or perform routine O&M.
            // Never store your AccessKey ID and AccessKey secret in your source code. Doing so may expose your credentials and compromise all resources under your account.
            // This example stores the AccessKey ID and AccessKey secret in environment variables. You can also store them in a configuration file as needed.
            authConfig.accessKeyId = System.getenv("CC_AK_ENV");
            authConfig.accessKeySecret = System.getenv("CC_SK_ENV");
            authConfig.type = "access_key";
            authConfig.regionId = "cn-shanghai"; // Replace this value with the region where your instance is deployed. For example, if your instance is deployed in China (Hangzhou), set regionId to "cn-hangzhou".
            authConfig.endpoint = "imagesearch.cn-shanghai.aliyuncs.com"; // Replace this value with the endpoint for your instance's region. For example, if your instance is deployed in China (Hangzhou), set endpoint to "imagesearch.cn-hangzhou.aliyuncs.com".
            
            // The following shows how to access the service over an internal network (VPC).
            // Note: Internal network (VPC) access is available only for ECS instances or other resources in the same region as your image search instance. For example, if your image search instance is deployed in China (Shanghai), your ECS instance or other resources must also be deployed in China (Shanghai) to access the service over the VPC endpoint. Otherwise, the request fails. If you encounter failures, verify that your ECS instance or other resources are in the same region as your image search instance.
            // authConfig.endpointType = "internal";  // Required for internal network (VPC) access. Set this parameter to "internal".
            // authConfig.endpoint = "imagesearch-vpc.cn-shanghai.aliyuncs.com"; // Replace this value with the VPC endpoint for your instance's region. For example, if your instance is deployed in China (Hangzhou), set endpoint to "imagesearch-vpc.cn-hangzhou.aliyuncs.com".
            
    
            Client client = new Client(authConfig);
            IncreaseListRequest request = new IncreaseListRequest();
            // Required. The instance name of your image search service. Note: This is the instance name, not the instance ID. You can find it in the instance information section of the Alibaba Cloud console.
            request.instanceName = "XXXXXXXXX";
            // Optional. The batch task ID.
            request.setId(1470L);
            // Optional. The OSS bucket name.
            request.setBucketName("BucketName");
            // Optional. The OSS path.
            request.setPath("/localization/xxxx");
            // Optional. The starting page number. Default: 1.
            request.setPageNumber(1);
            // Optional. The number of entries per page. Default: 20.
            request.setPageSize(1);
            IncreaseListResponse response = client.increaseList(request);
            System.out.println(response.getBody().toMap()); 
        }
    }
  • Sample response

    {
      RequestId=56E7E6CC-64AB-17CA-A7CD-1948FB953B8C,
      Data={
        TotalCount=1,
        PageSize=1,
        PageNumber=1,
        Increments={
          Instance=[
            {
              Msg=success,
              Status=NORMAL,
              Path=/xx/xx,
              BucketName=bucketName,
              UtcCreate=1639107872000,
              ErrorUrl=https://example.com/xxx?Expires=1670661540&xxx=xx,
              UtcModified=1639125540000,
              Id=1464,
              CallbackAddress=null,
              Code=0
            }
          ]
        }
      }
    }

CompareSimilarByImage API

  • Code example

    package com.aliyun.sample;
    
    import com.aliyun.imagesearch20201214.Client;
    import com.aliyun.imagesearch20201214.models.CompareSimilarByImageAdvanceRequest;
    import com.aliyun.imagesearch20201214.models.CompareSimilarByImageResponse;
    import com.aliyun.tea.TeaException;
    import com.aliyun.teautil.models.RuntimeOptions;
    import com.aliyun.teaopenapi.models.Config;
    
    import java.io.FileInputStream;
    import java.io.InputStream;
    
    public class compareSimilarByImage {
        public static void main(String[] args) throws Exception {
            Config authConfig = new Config();
            // Create an AK/SK pair: https://help.aliyun.com/document_detail/116401.htm
            // An Alibaba Cloud account's AccessKey pair has permissions to call all APIs. We recommend that you use a Resource Access Management (RAM) user to call APIs or perform routine O&M.
            // Never store your AccessKey ID and AccessKey secret in your source code. Doing so may expose your credentials and compromise all resources under your account.
            // This example stores the AccessKey ID and AccessKey secret in environment variables. You can also store them in a configuration file as needed.
            authConfig.accessKeyId = System.getenv("CC_AK_ENV");
            authConfig.accessKeySecret = System.getenv("CC_SK_ENV");
            authConfig.type = "access_key";
            authConfig.regionId = "cn-shanghai"; // Replace this value with the region where your instance is deployed. For example, if your instance is deployed in China (Hangzhou), set regionId to "cn-hangzhou".
            authConfig.endpoint = "imagesearch.cn-shanghai.aliyuncs.com"; // Replace this value with the endpoint for your instance's region. For example, if your instance is deployed in China (Hangzhou), set endpoint to "imagesearch.cn-hangzhou.aliyuncs.com".
    
            // The following shows how to access the service over an internal network (VPC).
            // Note: Internal network (VPC) access is available only for ECS instances or other resources in the same region as your image search instance. For example, if your image search instance is deployed in China (Shanghai), your ECS instance or other resources must also be deployed in China (Shanghai) to access the service over the VPC endpoint. Otherwise, the request fails. If you encounter failures, verify that your ECS instance or other resources are in the same region as your image search instance.
            // authConfig.endpointType = "internal";  // Required for internal network (VPC) access. Set this parameter to "internal".
            // authConfig.endpoint = "imagesearch-vpc.cn-shanghai.aliyuncs.com"; // Replace this value with the VPC endpoint for your instance's region. For example, if your instance is deployed in China (Hangzhou), set endpoint to "imagesearch-vpc.cn-hangzhou.aliyuncs.com".
    
            Client client = new Client(authConfig);
            CompareSimilarByImageAdvanceRequest compareSimilarByImageAdvanceRequest = new CompareSimilarByImageAdvanceRequest();
            // Required. The instance name of your image search service. Note: This is the instance name, not the instance ID. You can find it in the instance information section of the Alibaba Cloud console.
            compareSimilarByImageAdvanceRequest.setInstanceName("XXXXXXXXX");
            String primaryName = "D:/1.jpg";
            String secondaryName = "D:/2.jpg";
            try {
    
                // The following commented code shows how to provide image URLs.
                // String primaryUrl = "https://www.example.com/1.jpg";
                // String secondaryUrl = "https://www.example.com/2.jpg";
                // compareSimilarByImageAdvanceRequest.setPrimaryPicContentObject(new URL(primaryUrl).openStream());
                // compareSimilarByImageAdvanceRequest.setSecondaryPicContentObject(new URL(secondaryUrl).openStream());
    
    
                // The following uploads image files.
                InputStream primaryInputStream = new FileInputStream(primaryName);
                InputStream secondaryInputStream = new FileInputStream(secondaryName);
                compareSimilarByImageAdvanceRequest.setPrimaryPicContentObject(primaryInputStream);
                compareSimilarByImageAdvanceRequest.setSecondaryPicContentObject(secondaryInputStream);
                RuntimeOptions runtimeOptions = new RuntimeOptions();
                CompareSimilarByImageResponse compareSimilarByImageResponse = client.compareSimilarByImageAdvance(compareSimilarByImageAdvanceRequest, runtimeOptions);
                System.out.println(compareSimilarByImageResponse.getBody().toMap());
            } catch (TeaException e) {
                System.out.println(e.getCode());
                System.out.println(e.getData());
                System.out.println(e.getMessage());
                e.printStackTrace();
            }
          }
       }
    }
    
  • Sample response

    {
      Msg=success, 
      Score=1.0, 
      RequestId=5C0F29D6-D5DA-1068-9A6A-F68B07F8E02F, 
      Code=200, 
      Success=true
    }

CheckImageExists API

  • Code example

    package com.demo;
    
    import com.aliyun.imagesearch20201214.Client;
    import com.aliyun.imagesearch20201214.models.*;
    import com.aliyun.tea.TeaException;
    import com.aliyun.teaopenapi.models.Config;
    import com.aliyun.teautil.models.RuntimeOptions;
    
    public class CheckImageExists {
        public static void main(String[] args) throws Exception {
            Config authConfig = new Config();
            // Create an AK/SK pair: https://help.aliyun.com/document_detail/116401.htm
            // An Alibaba Cloud account's AccessKey pair has permissions to call all APIs. We recommend that you use a Resource Access Management (RAM) user to call APIs or perform routine O&M.
            // Never store your AccessKey ID and AccessKey secret in your source code. Doing so may expose your credentials and compromise all resources under your account.
            // This example stores the AccessKey ID and AccessKey secret in environment variables. You can also store them in a configuration file as needed.
            authConfig.accessKeyId = System.getenv("CC_AK_ENV");
            authConfig.accessKeySecret = System.getenv("CC_SK_ENV");
            authConfig.type = "access_key";
            // Replace this value with the region where your instance is deployed. For example, if your instance is deployed in China (Hangzhou), set regionId to "cn-hangzhou".
            authConfig.regionId = "cn-shanghai";
            // Replace this value with the endpoint for your instance's region. For example, if your instance is deployed in China (Hangzhou), set endpoint to "imagesearch.cn-hangzhou.aliyuncs.com".
            authConfig.endpoint = "imagesearch.cn-shanghai.aliyuncs.com"; 
            
            // The following shows how to access the service over an internal network (VPC).
            // Note: Internal network (VPC) access is available only for ECS instances or other resources in the same region as your image search instance. For example, if your image search instance is deployed in China (Shanghai), your ECS instance or other resources must also be deployed in China (Shanghai) to access the service over the VPC endpoint. Otherwise, the request fails. If you encounter failures, verify that your ECS instance or other resources are in the same region as your image search instance.
            // authConfig.endpointType = "internal";  // Required for internal network (VPC) access. Set this parameter to "internal".
            // authConfig.endpoint = "imagesearch-vpc.cn-shanghai.aliyuncs.com"; // Replace this value with the VPC endpoint for your instance's region. For example, if your instance is deployed in China (Hangzhou), set endpoint to "imagesearch-vpc.cn-hangzhou.aliyuncs.com".
            Client client = new Client(authConfig);
            CheckImageExistsRequest request = new CheckImageExistsRequest();
            // Required. The instance name of your image search service. Note: This is the instance name, not the instance ID. You can find it in the instance information section of the Alibaba Cloud console.
            request.instanceName = "ceshi123qweass1";
            // Required. The image name. Maximum length: 256 characters.
            // ProductId + PicName uniquely identifies an image.
            request.picName = "123";
            // Required. The product ID. Maximum length: 256 characters.
            // A product can have multiple images.
            request.productId = "123";
            RuntimeOptions runtimeObject = new RuntimeOptions();
            try {
                CheckImageExistsResponse response = client.checkImageExistsWithOptions(request, runtimeObject);
                System.out.println(response.getBody().toMap());
                System.out.println(response.getBody().requestId);
            } catch (TeaException e) {
                System.out.println(e.getCode());
                System.out.println(e.getData());
                System.out.println(e.getMessage());
                e.printStackTrace();
            }
        }
    }
  • Sample response

    {Msg=success, RequestId=xxx-xxx-xxx-xxx-xxxxx, Exists=true, Auctions={CategoryId=88888888, PicName=123, ProductId=123, IntAttr4=null, IntAttr3=null, IntAttr2=null, CustomContent=null, StrAttr4=null, StrAttr3=null, StrAttr2=null, IntAttr=null, StrAttr=null}, Code=0, Success=true}
    xxx-xxx-xxx-xxx-xxxxx