Tous les produits
Search
Centre de documentation

Image Search:SDK pour Java

Dernière mise à jour :Aug 09, 2026

Cette rubrique décrit l'utilisation du SDK Image Search pour Java et fournit des exemples de code.

Méthodes

|
**Méthode**
|
**Description**
| | --- | --- | |
Add
|
Ajoute une image.
| |
SearchImageByPic
|
Recherche des images similaires à partir d'une image.
| |
SearchImageByName
|
Recherche des images similaires à partir du nom d'une image existante dans la galerie d'images.
| |
SearchImageByFilter
|
Recherche des images similaires à l'aide de filtres.
| |
Delete
|
Supprime une ou plusieurs images.
| |
UpdateImage
|
Met à jour une image.
| |
Detail
|
Interroge les informations de l'instance.
| |
DumpMeta
|
Crée une tâche pour exporter les métadonnées.
| |
DumpMetaList
|
Interroge la liste des tâches utilisées pour exporter les métadonnées.
| |
BatchTask
|
Crée une tâche par lot.
| |
BatchTaskList
|
Interroge la liste des tâches utilisées pour effectuer des opérations par lot.
| |
CompareSimilarByImage
|
Compare la similarité entre deux images.
| |
CheckImageExists
|
Vérifie si l'image existe.
|























































Préparatifs

  • Avant d'installer et d'utiliser un SDK Alibaba Cloud, assurez-vous d'avoir créé un compte Alibaba Cloud et d'avoir obtenu la paire AccessKey de ce compte. Pour plus d'informations, consultez la page Créer une paire AccessKey.

  • Ajoutez le SDK Image Search pour Java à votre projet.

    Importez le SDK Image Search pour Java en tant que dépendance Maven et ajoutez-le à votre projet.

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

Add

  • Exemple de 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 RAM user to call API operations or perform routine O&M. 
            // We recommend that you do not hard code your AccessKey ID and 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 pair in the 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 = "ap-southeast-1"; // 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 Singapore, set the regionId parameter to ap-southeast-1.
            authConfig.endpoint = "imagesearch.ap-southeast-1.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 Singapore, set the endpoint parameter to imagesearch.ap-southeast-1.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 Singapore, you can use a VPC endpoint to call the Image Search API only from the ECS instances or resources that reside in Singapore. 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.ap-southeast-1.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 Singapore, set the endpoint parameter to imagesearch-vpc.ap-southeast-1.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 cannot exceed 256 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 256 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 and generic image searches, the length and the width of an image must range from 100 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();
            }
        }
    }
  • Exemple de réponse

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

SearchImageByPic

  • Exemple de 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 and 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 pair in the 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 = "ap-southeast-1"; // 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 Singapore, set the regionId parameter to ap-southeast-1.
            authConfig.endpoint = "imagesearch.ap-southeast-1.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 Singapore, set the endpoint parameter to imagesearch.ap-southeast-1.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 Singapore, you can use a VPC endpoint to call the Image Search API only from the ECS instances or resources that reside in Singapore. 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.ap-southeast-1.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 Singapore, set the endpoint parameter to imagesearch-vpc.ap-southeast-1.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:in, not in, >, >=, <, <=, and =. str_attr supports the in, not in, = 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\"";
            // Optional. similarity threshold.
            // After specifying the similarity score threshold, only images with a similarity score greater than or equal to the threshold will be returned. The threshold range is 0.00-1.00, with a maximum of two decimal places; the default value is 0.00.
            request.scoreThreshold="0.54";
            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 and generic image searches, the length and the width of an image must range from 100 pixels to 4,096 pixels.
            // The image cannot contain rotation properties.
            request.num = 10;
            request.start = 0;
            // Optional. If the value is set to true, the response data is returned based on the ProductId parameter. 
            request.distinctProductId=false;
            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();
            }
        }
    }
  • Exemple de réponse

    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

  • Exemple de 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 and 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 pair in the 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 = "ap-southeast-1"; // 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 Singapore, set the regionId parameter to ap-southeast-1.
            authConfig.endpoint = "imagesearch.ap-southeast-1.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 Singapore, set the endpoint parameter to imagesearch.ap-southeast-1.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 Singapore, you can use a VPC endpoint to call the Image Search API only from the ECS instances or resources that reside in Singapore. 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.ap-southeast-1.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 Singapore, set the endpoint parameter to imagesearch-vpc.ap-southeast-1.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 cannot exceed 256 characters in length. 
            // A product ID can correspond to multiple image names. 
            request.productId = "test";
            // Required. The image name. The name can be up to 256 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:in, not in, >, >=, <, <=, and =. str_attr supports the in, not in, = 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\"";
            // Optional. similarity threshold.
            // After specifying the similarity score threshold, only images with a similarity score greater than or equal to the threshold will be returned. The threshold range is 0.00-1.00, with a maximum of two decimal places; the default value is 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();
            }
        }
    }
  • Exemple de réponse

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

SearchImageByFilter

  • Exemple de code

    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();
            // 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 and 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 pair in the 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 = "ap-southeast-1"; // 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 Singapore, set the regionId parameter to ap-southeast-1.
            authConfig.endpoint = "imagesearch.ap-southeast-1.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 Singapore, set the endpoint parameter to imagesearch.ap-southeast-1.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 Singapore, you can use a VPC endpoint to call the Image Search API only from the ECS instances or resources that reside in Singapore. 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.ap-southeast-1.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 Singapore, set the endpoint parameter to imagesearch-vpc.ap-southeast-1.aliyuncs.com.
            
    
            Client client = new Client(authConfig);
            SearchImageByFilterRequest request = new SearchImageByFilterRequest();
            // 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 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;
            // Required. The filter conditions.
            // int_attr supports the following operators:in, not in, >, >=, <, <=, and =. str_attr supports the in, not in, = 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\" 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();
            }
         }
    }
  • Exemple de réponse

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

Delete

  • Exemple de 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 and 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 pair in the 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 = "ap-southeast-1"; // 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 Singapore, set the regionId parameter to ap-southeast-1.
            authConfig.endpoint = "imagesearch.ap-southeast-1.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 Singapore, set the endpoint parameter to imagesearch.ap-southeast-1.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 Singapore, you can use a VPC endpoint to call the Image Search API only from the ECS instances or resources that reside in Singapore. 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.ap-southeast-1.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 Singapore, set the endpoint parameter to imagesearch-vpc.ap-southeast-1.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 if the isDeleteByFilter parameter is set to false. The product ID can be up to 256 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 image name. If you do not set this parameter, the system deletes all the images that correspond to the specified product ID. If you set this parameter, the system deletes only the image that is specified by the product_id and pic_name parameters. 
            request.picName = "1000";
            // Optional. If set to true, deletion will be performed based on filter or filter+productId.
            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();
            }
        }
    }
  • Exemple de réponse

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

UpdateImage

  • Exemple de 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 and 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 pair in the 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 = "ap-southeast-1"; // 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 Singapore, set the regionId parameter to ap-southeast-1.
            authConfig.endpoint = "imagesearch.ap-southeast-1.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 Singapore, set the endpoint parameter to imagesearch.ap-southeast-1.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 Singapore, you can use a VPC endpoint to call the Image Search API only from the ECS instances or resources that reside in Singapore. 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.ap-southeast-1.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 Singapore, set the endpoint parameter to imagesearch-vpc.ap-southeast-1.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");
            // Optional. If the image name is left blank, modify the images under the ProductId section.
            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);     
        }
    }
  • Exemple de réponse

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

Detail

  • Exemple de 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 and 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 pair in the 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 = "ap-southeast-1"; // 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 Singapore, set the regionId parameter to ap-southeast-1.
            authConfig.endpoint = "imagesearch.ap-southeast-1.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 Singapore, set the endpoint parameter to imagesearch.ap-southeast-1.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 Singapore, you can use a VPC endpoint to call the Image Search API only from the ECS instances or resources that reside in Singapore. 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.ap-southeast-1.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 Singapore, set the endpoint parameter to imagesearch-vpc.ap-southeast-1.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());  
        }
    }
  • Exemple de réponse

    {
      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

  • Exemple de 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 and 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 pair in the 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 = "ap-southeast-1"; // 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 Singapore, set the regionId parameter to ap-southeast-1.
            authConfig.endpoint = "imagesearch.ap-southeast-1.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 Singapore, set the endpoint parameter to imagesearch.ap-southeast-1.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 Singapore, you can use a VPC endpoint to call the Image Search API only from the ECS instances or resources that reside in Singapore. 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.ap-southeast-1.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 Singapore, set the endpoint parameter to imagesearch-vpc.ap-southeast-1.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());  
        }
    }
  • Exemple de réponse

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

DumpMetaList

  • Exemple de 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 and 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 pair in the 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 = "ap-southeast-1"; // 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 Singapore, set the regionId parameter to ap-southeast-1.
            authConfig.endpoint = "imagesearch.ap-southeast-1.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 Singapore, set the endpoint parameter to imagesearch.ap-southeast-1.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 Singapore, you can use a VPC endpoint to call the Image Search API only from the ECS instances or resources that reside in Singapore. 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.ap-southeast-1.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 Singapore, set the endpoint parameter to imagesearch-vpc.ap-southeast-1.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()); 
        }
    }
  • Exemple de réponse

    {
      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

  • Exemple de 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 and 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 pair in the 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 = "ap-southeast-1"; // 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 Singapore, set the regionId parameter to ap-southeast-1.
            authConfig.endpoint = "imagesearch.ap-southeast-1.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 Singapore, set the endpoint parameter to imagesearch.ap-southeast-1.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 Singapore, you can use a VPC endpoint to call the Image Search API only from the ECS instances or resources that reside in Singapore. 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.ap-southeast-1.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 Singapore, set the endpoint parameter to imagesearch-vpc.ap-southeast-1.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()); 
        }
    }
  • Exemple de réponse

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

BatchTaskList

  • Exemple de 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 and 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 pair in the 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 = "ap-southeast-1"; // 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 Singapore, set the regionId parameter to ap-southeast-1.
            authConfig.endpoint = "imagesearch.ap-southeast-1.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 Singapore, set the endpoint parameter to imagesearch.ap-southeast-1.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 Singapore, you can use a VPC endpoint to call the Image Search API only from the ECS instances or resources that reside in Singapore. 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.ap-southeast-1.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 Singapore, set the endpoint parameter to imagesearch-vpc.ap-southeast-1.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()); 
        }
    }
  • Exemple de réponse

    {
      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

  • Exemple de code

    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();
            // 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 and 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 pair in the 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 = "ap-southeast-1"; // 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 Singapore, set the regionId parameter to ap-southeast-1.
            authConfig.endpoint = "imagesearch.ap-southeast-1.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 Singapore, set the endpoint parameter to imagesearch.ap-southeast-1.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 Singapore, you can use a VPC endpoint to call the Image Search API only from the ECS instances or resources that reside in Singapore. 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.ap-southeast-1.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 Singapore, set the endpoint parameter to imagesearch-vpc.ap-southeast-1.aliyuncs.com.
            
    
            Client client = new Client(authConfig);
            CompareSimilarByImageAdvanceRequest compareSimilarByImageAdvanceRequest = new CompareSimilarByImageAdvanceRequest();
            // 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.
            compareSimilarByImageAdvanceRequest.setInstanceName("XXXXXXXXX");
            String primaryName = "D:/1.jpg";
            String secondaryName = "D:/2.jpg";
            try {
    
                // The following sample code provides an example on how to specify an image URL: 
                // 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 sample code provides an example on how to upload an image file: 
                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();
            }
          }
       }
    }
    
  • Exemple de réponse

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

CheckImageExists

  • Exemple de code

    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();
            // 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 and 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 pair in the 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";
            // 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 Singapore, set the regionId parameter to ap-southeast-1.
            authConfig.regionId = "ap-southeast-1"; 
            // 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 Singapore, set the endpoint parameter to imagesearch.ap-southeast-1.aliyuncs.com.
            authConfig.endpoint = "imagesearch.ap-southeast-1.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 Singapore, you can use a VPC endpoint to call the Image Search API only from the ECS instances or resources that reside in Singapore. 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.ap-southeast-1.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 Singapore, set the endpoint parameter to imagesearch-vpc.ap-southeast-1.aliyuncs.com.
            Client client = new Client(authConfig);
            CheckImageExistsRequest request = new CheckImageExistsRequest();
            // 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 = "xxxx";
            // Required. The ID of the product. The ID cannot exceed 256 characters in length. 
            // A product ID can correspond to multiple image names. 
            request.productId = "123";
            // Required. The image name. The name can be up to 256 characters in length. 
            // An image is uniquely identified by the values of the productId and picName parameters. 
            request.picName = "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();
            }
            
        }
    }
  • Exemple de réponse

    {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