All Products
Search
Document Center

Image Search:SDK for Java

Last Updated:Aug 23, 2024

This topic describes how to use Image Search SDK for Java and provides sample code.

Methods

Method

Description

Add

Adds an image.

SearchImageByPic

Searches for similar images based on an image.

SearchImageByName

Searches for similar images based on the name of an existing image in the image gallery.

Delete

Removes one or more images.

UpdateImage

Updates an image.

Detail

Queries the information about an instance.

DumpMeta

Creates a task to export metadata.

DumpMetaList

Queries a list of tasks that are used to export metadata.

BatchTask

Creates a batch task.

BatchTaskList

Queries a list of tasks that are used to perform batch operations.

Preparations

  • Before you install and use an Alibaba Cloud SDK, make sure that you have created an Alibaba Cloud account and obtained the AccessKey pair of the Alibaba Cloud account. For more information, see Obtain an AccessKey pair.

  • Add Image Search SDK for Java to your project.

    Import Image Search SDK for Java as a Maven dependency, and add the SDK to your project.

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

Add

  • Sample code

    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.io.FileInputStream;
    import java.net.URL;
    import java.io.InputStream;
    public class Add {
        public static void main(String[] args) throws Exception {
            Config authConfig = new Config();
            // For information about how to create an AccessKey pair, see "Create an AccessKey pair" at https://www.alibabacloud.com/help/en/resource-access-management/latest/accesskey-pairs-create-an-accesskey-pair-for-a-ram-user.
            // The AccessKey pair of an Alibaba Cloud account has the permissions to call all API operations. We recommend that you use the AccessKey pair of a Resource Access Management (RAM) user to call API operations or perform routine O&M. 
            // We recommend that you do not hard code your AccessKey ID or AccessKey secret in your project code. Otherwise, the AccessKey pair may be leaked and the security of all resources within your account is compromised. 
            // In this example, the AccessKey ID and AccessKey secret are saved as environment variables. You can also save the AccessKey ID and AccessKey secret to a configuration file based on your business requirements. 
            authConfig.accessKeyId = System.getenv("CC_AK_ENV");
            authConfig.accessKeySecret = System.getenv("CC_SK_ENV");
            authConfig.type = "access_key";
            authConfig.regionId = "cn-shanghai"; // Replace the value with the ID of the region in which your Image Search instance resides. For example, if your Image Search instance resides in the China (Hangzhou) region, set the regionId parameter to cn-hangzhou.
            authConfig.endpoint = "imagesearch.cn-shanghai.aliyuncs.com"; // Replace the value with the endpoint in the region in which your Image Search instance resides. For example, if your Image Search instance resides in the China (Hangzhou) region, set the endpoint parameter to imagesearch.cn-hangzhou.aliyuncs.com.
            
            // The following sample code provides an example on how to use a virtual private cloud (VPC) endpoint to call the Image Search API.
            // Note: You can use a VPC endpoint to call the Image Search API only from Elastic Compute Service (ECS) instances or resources that reside in the same region. For example, if your Image Search instance resides in the China (Shanghai) region, you can use a VPC endpoint to call the Image Search API only from the ECS instances or resources that reside in the China (Shanghai) region. Otherwise, the API operation fails to be called. In case of a failed API call, check whether your ECS instances or resources are in the same region as your Image Search instance before you call the Image Search API. 
            // authConfig.endpointType = "internal";  // If you want to use a VPC endpoint to call the Image Search API, you must specify the endpointType parameter and set the value to internal.
            // authConfig.endpoint = "imagesearch-vpc.cn-shanghai.aliyuncs.com"; // The VPC endpoint that is used to call the Image Search API. Replace the value with the VPC endpoint in the region in which your Image Search instance resides. For example, if your Image Search instance resides in the China (Hangzhou) region, set the endpoint parameter to imagesearch-vpc.cn-hangzhou.aliyuncs.com.
            
            
            Client client = new Client(authConfig);
            AddImageAdvanceRequest request = new AddImageAdvanceRequest();
            // Required. The name of the Image Search instance. Enter the instance name instead of the instance ID. After an Image Search instance is purchased, you can view the instance name on the instance list page of the Image Search console.
            request.instanceName = "XXXXXXXXXXX";
            // Required. The ID of the product. The ID can be up to 512 characters in length. 
            // A product ID can correspond to multiple image names. 
            request.productId = "test";
            // Required. The name of the image. The name can be up to 512 characters in length. 
            // 1. An image is uniquely identified by the values of the productId and picName parameters. 
            // 2. If you add an image whose product ID (productId) and image name (picName) are the same as those of an existing image, the newly added image overwrites the existing image. 
            request.picName = "1000";
            // Optional. The ID of the product category. 
            // 1. Product image search: If a category is specified, the specified category prevails. If no category is specified, the system predicts and selects a category. The category selected by the system is included in the response. 
            // 2. Generic image search: The category ID is set to 88888888 regardless of whether a category is specified. 
            request.categoryId = 3;
            // Optional. The user-defined content. The value can be up to 4,096 characters in length. 
            // If you specify this parameter, the response includes this parameter and its value. You can add text such as an image description. 
            request.customContent = "this is a simple test";
            // Optional. The attribute of the INT type. The attribute can be used to filter images during image searches. If you specify this parameter, the response includes this parameter and its value. 
            // For example, you can set different attributes for images from different sites or different users. This way, users can filter images by attribute and obtain more accurate search results.
            request.intAttr = 56;
            // Optional. The attribute of the STRING type. The value can be up to 128 characters in length. The attribute can be used to filter images during image searches. If you specify this parameter, the response includes this parameter and its value. 
            request.strAttr = "test";
            // Optional. Specifies whether to identify the subject in the image. Default value: true. 
            // 1. If you set this parameter to true, the system identifies the subject in the image and searches for images based on the identified subject. The response includes the identification result. 
            // 2. If you set this parameter to false, the system searches for images based on the entire image without subject identification. 
            request.crop = true;
            // Optional. The subject area of the image, in the format of x1,x2,y1,y2. Specifically, x1 and y1 specify the upper-left point, and x2 and y2 specify the lower-right point. The specified area cannot cross the boundary of the image. 
            // If you specify the region parameter, the search is conducted based on the value of the region parameter regardless of the value of the crop parameter. 
            request.region = "167,467,221,407";
            RuntimeOptions runtimeOptions = new RuntimeOptions();
            String picName = "D:/123.jpg";      
            try {            
               // The image. The image cannot exceed 4 MB in size. The transmission timeout period cannot exceed 5 seconds. Only the following image formats are supported: PNG, JPG, JPEG, BMP, GIF, WebP, TIFF, and PPM.
               // For product, trademark, and generic image searches, the length and the width of an image must range from 100 pixels to 4,096 pixels.
               // For fabric image search, the length and the width of an image must range from 448 pixels to 4,096 pixels.
               // The image cannot contain rotation properties.
    
               // The following sample code provides an example on how to specify an image URL: 
               // String url = "https://www.example.com/123.jpg"; 
               // request.picContentObject = new URL(url).openStream();
               // The following sample code provides an example on how to upload 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

  • Sample code

    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();
            // For information about how to create an AccessKey pair, see "Create an AccessKey pair" at https://www.alibabacloud.com/help/en/resource-access-management/latest/accesskey-pairs-create-an-accesskey-pair-for-a-ram-user.
            // The AccessKey pair of an Alibaba Cloud account has the permissions to call all API operations. We recommend that you use the AccessKey pair of a RAM user to call API operations or perform routine O&M. 
            // We recommend that you do not hard code your AccessKey ID or AccessKey secret in your project code. Otherwise, the AccessKey pair may be leaked and the security of all resources within your account is compromised. 
            // In this example, the AccessKey ID and AccessKey secret are saved as environment variables. You can also save the AccessKey ID and AccessKey secret to a configuration file based on your business requirements. 
            authConfig.accessKeyId = System.getenv("CC_AK_ENV");
            authConfig.accessKeySecret = System.getenv("CC_SK_ENV");
            authConfig.type = "access_key";
            authConfig.regionId = "cn-shanghai"; // Replace the value with the ID of the region in which your Image Search instance resides. For example, if your Image Search instance resides in the China (Hangzhou) region, set the regionId parameter to cn-hangzhou.
            authConfig.endpoint = "imagesearch.cn-shanghai.aliyuncs.com"; // Replace the value with the endpoint in the region in which your Image Search instance resides. For example, if your Image Search instance resides in the China (Hangzhou) region, set the endpoint parameter to imagesearch.cn-hangzhou.aliyuncs.com.
            
            // The following sample code provides an example on how to use a VPC endpoint to call the Image Search API.
            // Note: You can use a VPC endpoint to call the Image Search API only from ECS instances or resources that reside in the same region. For example, if your Image Search instance resides in the China (Shanghai) region, you can use a VPC endpoint to call the Image Search API only from the ECS instances or resources that reside in the China (Shanghai) region. Otherwise, the API operation fails to be called. In case of a failed API call, check whether your ECS instances or resources are in the same region as your Image Search instance before you call the Image Search API. 
            // authConfig.endpointType = "internal";  // If you want to use a VPC endpoint to call the Image Search API, you must specify the endpointType parameter and set the value to internal.
            // authConfig.endpoint = "imagesearch-vpc.cn-shanghai.aliyuncs.com"; // The VPC endpoint that is used to call the Image Search API. Replace the value with the VPC endpoint in the region in which your Image Search instance resides. For example, if your Image Search instance resides in the China (Hangzhou) region, set the endpoint parameter to imagesearch-vpc.cn-hangzhou.aliyuncs.com.
            
    
            Client client = new Client(authConfig);
            SearchImageByPicAdvanceRequest request = new SearchImageByPicAdvanceRequest();
            // Required. The name of the Image Search instance. Enter the instance name instead of the instance ID. After an Image Search instance is purchased, you can view the instance name on the instance list page of the Image Search console.
            request.instanceName = "XXXXXXXXX";
            // Optional. The ID of the product category. 
            // 1. Product image search: If a category is specified, the specified category prevails. If no category is specified, the system predicts and selects a category. The category selected by the system is included in the response. 
            // 2. Generic image search: The category ID is set to 88888888 regardless of whether a category is specified. 
            request.categoryId = 3;
            // Optional. The number of entries to be returned. Valid values: 1 to 100. Default value: 10. 
            request.num = 10;
            // Optional. The ordinal number of the first entry to be returned. Valid values: 0 to 499. Default value: 0. 
            request.start = 0;
            // Optional. Specifies whether to identify the subject in the image. Default value: true. 
            // 1. If you set this parameter to true, the system identifies the subject in the image and searches for images based on the identified subject. The response includes the identification result. 
            // 2. If you set this parameter to false, the system searches for images based on the entire image without subject identification. 
            request.crop = true;
            // Optional. The subject area of the image, in the format of x1,x2,y1,y2. Specifically, x1 and y1 specify the upper-left point, and x2 and y2 specify the lower-right point. The specified area cannot cross the boundary of the image. 
            // If you specify the region parameter, the search is conducted based on the value of the region parameter regardless of the value of the crop parameter. 
            request.region="167,467,221,407";
            // Optional. The filter conditions.
            // int_attr supports the following operators: >, >=, <, <=, and =. str_attr supports the = and != operators. You can set the logical operator between conditions to AND or OR. 
            // Examples:
            // 1. Filter images based on the attribute of the INT type: int_attr>=100.
            // 2. Filter images based on the attribute of the STRING type: str_attr!="value1".
            // 3. Filter images based on the attributes of the INT and STRING types: int_attr=1000 AND str_attr="value1".
            request.filter="int_attr=56 AND str_attr=\"test\"";
            String picName = "D:/123.jpg";
            // The image. The image cannot exceed 4 MB in size. The transmission timeout period cannot exceed 5 seconds. Only the following image formats are supported: PNG, JPG, JPEG, BMP, GIF, WebP, TIFF, and PPM.
            // For product, trademark, and generic image searches, the length and the width of an image must range from 100 pixels to 4,096 pixels.
            // For fabric image search, the length and the width of an image must range from 448 pixels to 4,096 pixels.
            // The image cannot contain rotation properties.
            request.num = 10;
            request.start = 0;
            RuntimeOptions runtimeObject =  new RuntimeOptions();
            try {            
                // The following sample code provides an example on how to specify an image URL: 
                // String url = "https://www.example.com/123.jpg"; 
                // request.picContentObject = new URL(url).openStream();  
     
                // The following sample code provides an example on how to upload 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

  • Sample code

    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 {
            // The configurations.
            Config authConfig = new Config();
            // For information about how to create an AccessKey pair, see "Create an AccessKey pair" at https://www.alibabacloud.com/help/en/resource-access-management/latest/accesskey-pairs-create-an-accesskey-pair-for-a-ram-user.
            // The AccessKey pair of an Alibaba Cloud account has the permissions to call all API operations. We recommend that you use the AccessKey pair of a RAM user to call API operations or perform routine O&M. 
            // We recommend that you do not hard code your AccessKey ID or AccessKey secret in your project code. Otherwise, the AccessKey pair may be leaked and the security of all resources within your account is compromised. 
            // In this example, the AccessKey ID and AccessKey secret are saved as environment variables. You can also save the AccessKey ID and AccessKey secret to a configuration file based on your business requirements. 
            authConfig.accessKeyId = System.getenv("CC_AK_ENV");
            authConfig.accessKeySecret = System.getenv("CC_SK_ENV");
            authConfig.type = "access_key";
            authConfig.regionId = "cn-shanghai"; // Replace the value with the ID of the region in which your Image Search instance resides. For example, if your Image Search instance resides in the China (Hangzhou) region, set the regionId parameter to cn-hangzhou.
            authConfig.endpoint = "imagesearch.cn-shanghai.aliyuncs.com"; // Replace the value with the endpoint in the region in which your Image Search instance resides. For example, if your Image Search instance resides in the China (Hangzhou) region, set the endpoint parameter to imagesearch.cn-hangzhou.aliyuncs.com.
            
            // The following sample code provides an example on how to use a VPC endpoint to call the Image Search API.
            // Note: You can use a VPC endpoint to call the Image Search API only from ECS instances or resources that reside in the same region. For example, if your Image Search instance resides in the China (Shanghai) region, you can use a VPC endpoint to call the Image Search API only from the ECS instances or resources that reside in the China (Shanghai) region. Otherwise, the API operation fails to be called. In case of a failed API call, check whether your ECS instances or resources are in the same region as your Image Search instance before you call the Image Search API. 
            // authConfig.endpointType = "internal";  // If you want to use a VPC endpoint to call the Image Search API, you must specify the endpointType parameter and set the value to internal.
            // authConfig.endpoint = "imagesearch-vpc.cn-shanghai.aliyuncs.com"; // The VPC endpoint that is used to call the Image Search API. Replace the value with the VPC endpoint in the region in which your Image Search instance resides. For example, if your Image Search instance resides in the China (Hangzhou) region, set the endpoint parameter to imagesearch-vpc.cn-hangzhou.aliyuncs.com.
            
    
            Client client = new Client(authConfig);
            SearchImageByNameRequest request = new SearchImageByNameRequest();
            // Required. The name of the Image Search instance. Enter the instance name instead of the instance ID. After an Image Search instance is purchased, you can view the instance name on the instance list page of the Image Search console.
            request.instanceName = "XXXXXXXXX";
            // Required. The ID of the product. The ID can be up to 512 characters in length. 
            // A product ID can correspond to multiple image names. 
            request.productId = "test";
            // Required. The name of the image. The name can be up to 512 characters in length. 
            // An image is uniquely identified by the values of the productId and picName parameters. 
            request.picName = "1000";
            // Optional. The ID of the product category. 
            // 1. Product image search: If a category is specified, the specified category prevails. If no category is specified, the system predicts and selects a category. The category selected by the system is included in the response. 
            // 2. Generic image search: The category ID is set to 88888888 regardless of whether a category is specified. 
            request.categoryId = 3;
            // Optional. The number of entries to be returned. Valid values: 1 to 100. Default value: 10. 
            request.num =10;
            // Optional. The ordinal number of the first entry to be returned. Valid values: 0 to 499. Default value: 0. 
            request.start =0;
            // Optional. The filter conditions.
            // int_attr supports the following operators: >, >=, <, <=, and =. str_attr supports the = and != operators. You can set the logical operator between conditions to AND or OR. 
            // Examples:
            // 1. Filter images based on the attribute of the INT type: int_attr>=100.
            // 2. Filter images based on the attribute of the STRING type: str_attr!="value1".
            // 3. Filter images based on the attributes of the INT and STRING types: int_attr=1000 AND str_attr="value1".
            request.filter = "int_attr=56 AND str_attr =\"test\"";
            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
                        

Delete

  • Sample code

    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 "Create an AccessKey pair" at https://www.alibabacloud.com/help/en/resource-access-management/latest/accesskey-pairs-create-an-accesskey-pair-for-a-ram-user.
            // The AccessKey pair of an Alibaba Cloud account has the permissions to call all API operations. We recommend that you use the AccessKey pair of a RAM user to call API operations or perform routine O&M. 
            // We recommend that you do not hard code your AccessKey ID or AccessKey secret in your project code. Otherwise, the AccessKey pair may be leaked and the security of all resources within your account is compromised. 
            // In this example, the AccessKey ID and AccessKey secret are saved as environment variables. You can also save the AccessKey ID and AccessKey secret to a configuration file based on your business requirements. 
            authConfig.accessKeyId = System.getenv("CC_AK_ENV");
            authConfig.accessKeySecret = System.getenv("CC_SK_ENV");
            authConfig.type = "access_key";
            authConfig.regionId = "cn-shanghai"; // Replace the value with the ID of the region in which your Image Search instance resides. For example, if your Image Search instance resides in the China (Hangzhou) region, set the regionId parameter to cn-hangzhou.
            authConfig.endpoint = "imagesearch.cn-shanghai.aliyuncs.com"; // Replace the value with the endpoint in the region in which your Image Search instance resides. For example, if your Image Search instance resides in the China (Hangzhou) region, set the endpoint parameter to imagesearch.cn-hangzhou.aliyuncs.com.
            
            // The following sample code provides an example on how to use a VPC endpoint to call the Image Search API.
            // Note: You can use a VPC endpoint to call the Image Search API only from ECS instances or resources that reside in the same region. For example, if your Image Search instance resides in the China (Shanghai) region, you can use a VPC endpoint to call the Image Search API only from the ECS instances or resources that reside in the China (Shanghai) region. Otherwise, the API operation fails to be called. In case of a failed API call, check whether your ECS instances or resources are in the same region as your Image Search instance before you call the Image Search API. 
            // authConfig.endpointType = "internal";  // If you want to use a VPC endpoint to call the Image Search API, you must specify the endpointType parameter and set the value to internal.
            // authConfig.endpoint = "imagesearch-vpc.cn-shanghai.aliyuncs.com"; // The VPC endpoint that is used to call the Image Search API. Replace the value with the VPC endpoint in the region in which your Image Search instance resides. For example, if your Image Search instance resides in the China (Hangzhou) region, set the endpoint parameter to imagesearch-vpc.cn-hangzhou.aliyuncs.com.
            
    
            Client client = new Client(authConfig);
            DeleteImageRequest request = new DeleteImageRequest();
            // Required. The name of the Image Search instance. Enter the instance name instead of the instance ID. After an Image Search instance is purchased, you can view the instance name on the instance list page of the Image Search console.
            request.instanceName = "XXXXXXXXXXXX";
            // Required. The ID of the product. The ID can be up to 512 characters in length. 
            // A product ID can correspond to multiple image names. If you specify only this parameter and do not specify the picName parameter, the response includes the names of all the images that are removed.
            request.productId = "test";
             // Optional. The name of the image. If you do not specify this parameter, the system removes all the images that are related to the specified product ID. If you specify this parameter, the system removes only the image that is specified by the productId and picName parameters. 
            request.picName = "1000";
            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

  • Sample code

    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 "Create an AccessKey pair" at https://www.alibabacloud.com/help/en/resource-access-management/latest/accesskey-pairs-create-an-accesskey-pair-for-a-ram-user.
            // The AccessKey pair of an Alibaba Cloud account has the permissions to call all API operations. We recommend that you use the AccessKey pair of a RAM user to call API operations or perform routine O&M. 
            // We recommend that you do not hard code your AccessKey ID or AccessKey secret in your project code. Otherwise, the AccessKey pair may be leaked and the security of all resources within your account is compromised. 
            // In this example, the AccessKey ID and AccessKey secret are saved as environment variables. You can also save the AccessKey ID and AccessKey secret to a configuration file based on your business requirements. 
            authConfig.accessKeyId = System.getenv("CC_AK_ENV");
            authConfig.accessKeySecret = System.getenv("CC_SK_ENV");
            authConfig.type = "access_key";
            authConfig.regionId = "cn-shanghai"; // Replace the value with the ID of the region in which your Image Search instance resides. For example, if your Image Search instance resides in the China (Hangzhou) region, set the regionId parameter to cn-hangzhou.
            authConfig.endpoint = "imagesearch.cn-shanghai.aliyuncs.com"; // Replace the value with the endpoint in the region in which your Image Search instance resides. For example, if your Image Search instance resides in the China (Hangzhou) region, set the endpoint parameter to imagesearch.cn-hangzhou.aliyuncs.com.
            
            // The following sample code provides an example on how to use a VPC endpoint to call the Image Search API.
            // Note: You can use a VPC endpoint to call the Image Search API only from ECS instances or resources that reside in the same region. For example, if your Image Search instance resides in the China (Shanghai) region, you can use a VPC endpoint to call the Image Search API only from the ECS instances or resources that reside in the China (Shanghai) region. Otherwise, the API operation fails to be called. In case of a failed API call, check whether your ECS instances or resources are in the same region as your Image Search instance before you call the Image Search API. 
            // authConfig.endpointType = "internal";  // If you want to use a VPC endpoint to call the Image Search API, you must specify the endpointType parameter and set the value to internal.
            // authConfig.endpoint = "imagesearch-vpc.cn-shanghai.aliyuncs.com"; // The VPC endpoint that is used to call the Image Search API. Replace the value with the VPC endpoint in the region in which your Image Search instance resides. For example, if your Image Search instance resides in the China (Hangzhou) region, set the endpoint parameter to imagesearch-vpc.cn-hangzhou.aliyuncs.com.
            
    
            Client client = new Client(authConfig);
            UpdateImageRequest request = new UpdateImageRequest();
            // Required. The name of the Image Search instance. Enter the instance name instead of the instance ID. After an Image Search instance is purchased, you can view the instance name on the instance list page of the Image Search console.
            request.instanceName = "XXXXXXXXX";
            // Required. The ID of the product. The product ID cannot be changed. 
            request.setProductId("1");
            // Required. The name of the image. The image name cannot be changed. 
            request.setPicName("1");
            // Optional. The attribute of the INT type. The attribute can be used to filter images during image searches. If you specify this parameter, the response includes this parameter and its value. 
            request.setIntAttr(1);
            // Optional. The attribute of the STRING type. The value can be up to 128 characters in length. The attribute can be used to filter images during image searches. If you specify this parameter, the response includes this parameter and its value. 
            request.setStrAttr("test");
            // Optional. The user-defined content. The value can be up to 4,096 characters in length. 
            request.setCustomContent("This is a sample 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

  • Sample code

    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();
            // For information about how to create an AccessKey pair, see "Create an AccessKey pair" at https://www.alibabacloud.com/help/en/resource-access-management/latest/accesskey-pairs-create-an-accesskey-pair-for-a-ram-user.
            // The AccessKey pair of an Alibaba Cloud account has the permissions to call all API operations. We recommend that you use the AccessKey pair of a RAM user to call API operations or perform routine O&M. 
            // We recommend that you do not hard code your AccessKey ID or AccessKey secret in your project code. Otherwise, the AccessKey pair may be leaked and the security of all resources within your account is compromised. 
            // In this example, the AccessKey ID and AccessKey secret are saved as environment variables. You can also save the AccessKey ID and AccessKey secret to a configuration file based on your business requirements. 
            authConfig.accessKeyId = System.getenv("CC_AK_ENV");
            authConfig.accessKeySecret = System.getenv("CC_SK_ENV");
            authConfig.type = "access_key";
            authConfig.regionId = "cn-shanghai"; // Replace the value with the ID of the region in which your Image Search instance resides. For example, if your Image Search instance resides in the China (Hangzhou) region, set the regionId parameter to cn-hangzhou.
            authConfig.endpoint = "imagesearch.cn-shanghai.aliyuncs.com"; // Replace the value with the endpoint in the region in which your Image Search instance resides. For example, if your Image Search instance resides in the China (Hangzhou) region, set the endpoint parameter to imagesearch.cn-hangzhou.aliyuncs.com.
            
            // The following sample code provides an example on how to use a VPC endpoint to call the Image Search API.
            // Note: You can use a VPC endpoint to call the Image Search API only from ECS instances or resources that reside in the same region. For example, if your Image Search instance resides in the China (Shanghai) region, you can use a VPC endpoint to call the Image Search API only from the ECS instances or resources that reside in the China (Shanghai) region. Otherwise, the API operation fails to be called. In case of a failed API call, check whether your ECS instances or resources are in the same region as your Image Search instance before you call the Image Search API. 
            // authConfig.endpointType = "internal";  // If you want to use a VPC endpoint to call the Image Search API, you must specify the endpointType parameter and set the value to internal.
            // authConfig.endpoint = "imagesearch-vpc.cn-shanghai.aliyuncs.com"; // The VPC endpoint that is used to call the Image Search API. Replace the value with the VPC endpoint in the region in which your Image Search instance resides. For example, if your Image Search instance resides in the China (Hangzhou) region, set the endpoint parameter to imagesearch-vpc.cn-hangzhou.aliyuncs.com.
            
    
            Client client = new Client(authConfig);
            DetailRequest request = new DetailRequest();
            // Required. The name of the Image Search instance. Enter the instance name instead of the instance ID. After an Image Search instance is purchased, you can view the instance name on the instance list page of the Image Search 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

  • Sample code

    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();
            // For information about how to create an AccessKey pair, see "Create an AccessKey pair" at https://www.alibabacloud.com/help/en/resource-access-management/latest/accesskey-pairs-create-an-accesskey-pair-for-a-ram-user.
            // The AccessKey pair of an Alibaba Cloud account has the permissions to call all API operations. We recommend that you use the AccessKey pair of a RAM user to call API operations or perform routine O&M. 
            // We recommend that you do not hard code your AccessKey ID or AccessKey secret in your project code. Otherwise, the AccessKey pair may be leaked and the security of all resources within your account is compromised. 
            // In this example, the AccessKey ID and AccessKey secret are saved as environment variables. You can also save the AccessKey ID and AccessKey secret to a configuration file based on your business requirements. 
            authConfig.accessKeyId = System.getenv("CC_AK_ENV");
            authConfig.accessKeySecret = System.getenv("CC_SK_ENV");
            authConfig.type = "access_key";
            authConfig.regionId = "cn-shanghai"; // Replace the value with the ID of the region in which your Image Search instance resides. For example, if your Image Search instance resides in the China (Hangzhou) region, set the regionId parameter to cn-hangzhou.
            authConfig.endpoint = "imagesearch.cn-shanghai.aliyuncs.com"; // Replace the value with the endpoint in the region in which your Image Search instance resides. For example, if your Image Search instance resides in the China (Hangzhou) region, set the endpoint parameter to imagesearch.cn-hangzhou.aliyuncs.com.
            
            // The following sample code provides an example on how to use a VPC endpoint to call the Image Search API.
            // Note: You can use a VPC endpoint to call the Image Search API only from ECS instances or resources that reside in the same region. For example, if your Image Search instance resides in the China (Shanghai) region, you can use a VPC endpoint to call the Image Search API only from the ECS instances or resources that reside in the China (Shanghai) region. Otherwise, the API operation fails to be called. In case of a failed API call, check whether your ECS instances or resources are in the same region as your Image Search instance before you call the Image Search API. 
            // authConfig.endpointType = "internal";  // If you want to use a VPC endpoint to call the Image Search API, you must specify the endpointType parameter and set the value to internal.
            // authConfig.endpoint = "imagesearch-vpc.cn-shanghai.aliyuncs.com"; // The VPC endpoint that is used to call the Image Search API. Replace the value with the VPC endpoint in the region in which your Image Search instance resides. For example, if your Image Search instance resides in the China (Hangzhou) region, set the endpoint parameter to imagesearch-vpc.cn-hangzhou.aliyuncs.com.
            
    
            Client client = new Client(authConfig);
            DumpMetaRequest request = new DumpMetaRequest();
            // Required. The name of the Image Search instance. Enter the instance name instead of the instance ID. After an Image Search instance is purchased, you can view the instance name on the instance list page of the Image Search 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

  • Sample code

    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();
            // For information about how to create an AccessKey pair, see "Create an AccessKey pair" at https://www.alibabacloud.com/help/en/resource-access-management/latest/accesskey-pairs-create-an-accesskey-pair-for-a-ram-user.
            // The AccessKey pair of an Alibaba Cloud account has the permissions to call all API operations. We recommend that you use the AccessKey pair of a RAM user to call API operations or perform routine O&M. 
            // We recommend that you do not hard code your AccessKey ID or AccessKey secret in your project code. Otherwise, the AccessKey pair may be leaked and the security of all resources within your account is compromised. 
            // In this example, the AccessKey ID and AccessKey secret are saved as environment variables. You can also save the AccessKey ID and AccessKey secret to a configuration file based on your business requirements. 
            authConfig.accessKeyId = System.getenv("CC_AK_ENV");
            authConfig.accessKeySecret = System.getenv("CC_SK_ENV");
            authConfig.type = "access_key";
            authConfig.regionId = "cn-shanghai"; // Replace the value with the ID of the region in which your Image Search instance resides. For example, if your Image Search instance resides in the China (Hangzhou) region, set the regionId parameter to cn-hangzhou.
            authConfig.endpoint = "imagesearch.cn-shanghai.aliyuncs.com"; // Replace the value with the endpoint in the region in which your Image Search instance resides. For example, if your Image Search instance resides in the China (Hangzhou) region, set the endpoint parameter to imagesearch.cn-hangzhou.aliyuncs.com.
            
            // The following sample code provides an example on how to use a VPC endpoint to call the Image Search API.
            // Note: You can use a VPC endpoint to call the Image Search API only from ECS instances or resources that reside in the same region. For example, if your Image Search instance resides in the China (Shanghai) region, you can use a VPC endpoint to call the Image Search API only from the ECS instances or resources that reside in the China (Shanghai) region. Otherwise, the API operation fails to be called. In case of a failed API call, check whether your ECS instances or resources are in the same region as your Image Search instance before you call the Image Search API. 
            // authConfig.endpointType = "internal";  // If you want to use a VPC endpoint to call the Image Search API, you must specify the endpointType parameter and set the value to internal.
            // authConfig.endpoint = "imagesearch-vpc.cn-shanghai.aliyuncs.com"; // The VPC endpoint that is used to call the Image Search API. Replace the value with the VPC endpoint in the region in which your Image Search instance resides. For example, if your Image Search instance resides in the China (Hangzhou) region, set the endpoint parameter to imagesearch-vpc.cn-hangzhou.aliyuncs.com.
            
    
            Client client = new Client(authConfig);
            DumpMetaListRequest request = new DumpMetaListRequest();
            // Required. The name of the Image Search instance. Enter the instance name instead of the instance ID. After an Image Search instance is purchased, you can view the instance name on the instance list page of the Image Search console. 
            request.instanceName = "XXXXXXXXX";
            // Optional. The ID of the task that is used to export metadata.
            request.setId(567L);
            // Optional. The page number. Default value: 1.
            request.setPageNumber(1);
            // Optional. The number of entries per page. Default value: 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

  • Sample code

    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();
            // For information about how to create an AccessKey pair, see "Create an AccessKey pair" at https://www.alibabacloud.com/help/en/resource-access-management/latest/accesskey-pairs-create-an-accesskey-pair-for-a-ram-user.
            // The AccessKey pair of an Alibaba Cloud account has the permissions to call all API operations. We recommend that you use the AccessKey pair of a RAM user to call API operations or perform routine O&M. 
            // We recommend that you do not hard code your AccessKey ID or AccessKey secret in your project code. Otherwise, the AccessKey pair may be leaked and the security of all resources within your account is compromised. 
            // In this example, the AccessKey ID and AccessKey secret are saved as environment variables. You can also save the AccessKey ID and AccessKey secret to a configuration file based on your business requirements. 
            authConfig.accessKeyId = System.getenv("CC_AK_ENV");
            authConfig.accessKeySecret = System.getenv("CC_SK_ENV");
            authConfig.type = "access_key";
            authConfig.regionId = "cn-shanghai"; // Replace the value with the ID of the region in which your Image Search instance resides. For example, if your Image Search instance resides in the China (Hangzhou) region, set the regionId parameter to cn-hangzhou.
            authConfig.endpoint = "imagesearch.cn-shanghai.aliyuncs.com"; // Replace the value with the endpoint in the region in which your Image Search instance resides. For example, if your Image Search instance resides in the China (Hangzhou) region, set the endpoint parameter to imagesearch.cn-hangzhou.aliyuncs.com.
            
            // The following sample code provides an example on how to use a VPC endpoint to call the Image Search API.
            // Note: You can use a VPC endpoint to call the Image Search API only from ECS instances or resources that reside in the same region. For example, if your Image Search instance resides in the China (Shanghai) region, you can use a VPC endpoint to call the Image Search API only from the ECS instances or resources that reside in the China (Shanghai) region. Otherwise, the API operation fails to be called. In case of a failed API call, check whether your ECS instances or resources are in the same region as your Image Search instance before you call the Image Search API. 
            // authConfig.endpointType = "internal";  // If you want to use a VPC endpoint to call the Image Search API, you must specify the endpointType parameter and set the value to internal.
            // authConfig.endpoint = "imagesearch-vpc.cn-shanghai.aliyuncs.com"; // The VPC endpoint that is used to call the Image Search API. Replace the value with the VPC endpoint in the region in which your Image Search instance resides. For example, if your Image Search instance resides in the China (Hangzhou) region, set the endpoint parameter to imagesearch-vpc.cn-hangzhou.aliyuncs.com.
            
    
            Client client = new Client(authConfig);
            IncreaseInstanceRequest request = new IncreaseInstanceRequest();
            // Required. The name of the Image Search instance. Enter the instance name instead of the instance ID. After an Image Search instance is purchased, you can view the instance name on the instance list page of the Image Search console.
            request.instanceName = "XXXXXXXXX";
            // Required. If images are stored in an Object Storage Service (OSS) bucket, enter the bucket name.
            request.setBucketName("bucketName");
            // Required. The path in which the images are stored. The path must start with a forward slash (/) and cannot end with a forward slash (/).
            // Create a file named increment.meta in the path in which the images are stored. For more information, see "Perform batch operations" in User Guide. 
            request.setPath("/public/xxx");
            // Optional. The callback URL if the API call is successful. The URL must start with http:// or https://.
            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

  • Sample code

    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();
            // For information about how to create an AccessKey pair, see "Create an AccessKey pair" at https://www.alibabacloud.com/help/en/resource-access-management/latest/accesskey-pairs-create-an-accesskey-pair-for-a-ram-user.
            // The AccessKey pair of an Alibaba Cloud account has the permissions to call all API operations. We recommend that you use the AccessKey pair of a RAM user to call API operations or perform routine O&M. 
            // We recommend that you do not hard code your AccessKey ID or AccessKey secret in your project code. Otherwise, the AccessKey pair may be leaked and the security of all resources within your account is compromised. 
            // In this example, the AccessKey ID and AccessKey secret are saved as environment variables. You can also save the AccessKey ID and AccessKey secret to a configuration file based on your business requirements. 
            authConfig.accessKeyId = System.getenv("CC_AK_ENV");
            authConfig.accessKeySecret = System.getenv("CC_SK_ENV");
            authConfig.type = "access_key";
            authConfig.regionId = "cn-shanghai"; // Replace the value with the ID of the region in which your Image Search instance resides. For example, if your Image Search instance resides in the China (Hangzhou) region, set the regionId parameter to cn-hangzhou.
            authConfig.endpoint = "imagesearch.cn-shanghai.aliyuncs.com"; // Replace the value with the endpoint in the region in which your Image Search instance resides. For example, if your Image Search instance resides in the China (Hangzhou) region, set the endpoint parameter to imagesearch.cn-hangzhou.aliyuncs.com.
            
            // The following sample code provides an example on how to use a VPC endpoint to call the Image Search API.
            // Note: You can use a VPC endpoint to call the Image Search API only from ECS instances or resources that reside in the same region. For example, if your Image Search instance resides in the China (Shanghai) region, you can use a VPC endpoint to call the Image Search API only from the ECS instances or resources that reside in the China (Shanghai) region. Otherwise, the API operation fails to be called. In case of a failed API call, check whether your ECS instances or resources are in the same region as your Image Search instance before you call the Image Search API. 
            // authConfig.endpointType = "internal";  // If you want to use a VPC endpoint to call the Image Search API, you must specify the endpointType parameter and set the value to internal.
            // authConfig.endpoint = "imagesearch-vpc.cn-shanghai.aliyuncs.com"; // The VPC endpoint that is used to call the Image Search API. Replace the value with the VPC endpoint in the region in which your Image Search instance resides. For example, if your Image Search instance resides in the China (Hangzhou) region, set the endpoint parameter to imagesearch-vpc.cn-hangzhou.aliyuncs.com.
            
    
            Client client = new Client(authConfig);
            IncreaseListRequest request = new IncreaseListRequest();
            // Required. The name of the Image Search instance. Enter the instance name instead of the instance ID. After an Image Search instance is purchased, you can view the instance name on the instance list page of the Image Search console.
            request.instanceName = "XXXXXXXXX";
            // Optional. The ID of the batch task.
            request.setId(1470L);
            // Optional. The name of the OSS bucket.
            request.setBucketName("BucketName");
            // Optional. The path to the OSS bucket.
            request.setPath("/localization/xxxx");
            // Optional. The page number. Default value: 1.
            request.setPageNumber(1);
            // Optional. The number of entries per page. Default value: 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
            }
          ]
        }
      }
    }