All Products
Search
Document Center

Image Search:SDK for Go

Last Updated:Sep 19, 2023

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

Note

If you want to obtain more information about Image Search and contact technical support, submit your questions on the pre-sales online consulting page or join the DingTalk group (ID 35035130).

Methods

Method

Description

Add

Adds one or more images.

SearchImageByPic

Searches for similar images based on a new image.

SearchImageByName

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

Delete

Deletes one or more images.

UpdateImage

Updates an image.

Detail

Queries the information about an instance.

DumpMeta

Creates a task to export metadata.

DumpMetaList

Queries the 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.

  • Run the following command by using govendor to install Image Search SDK for Go:

go get github.com/alibabacloud-go/imagesearch-20201214/v4

Add

  • Sample code

    package main
    
    import (
        "fmt"
        "os"
        rpc "github.com/alibabacloud-go/darabonba-openapi/client"
        imagesearch "github.com/alibabacloud-go/imagesearch-20201214/v4/client"
        util "github.com/alibabacloud-go/tea-utils/service"
    )
    
    func main() {
        // Initialize config.
        // For information about how to create an AccessKey pair, visit 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 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 ID and AccessKey secret to a configuration file based on your business requirements. 
        var config = new(rpc.Config).SetAccessKeyId(os.Getenv("CC_AK_ENV")).
            SetAccessKeySecret(os.Getenv("CC_SK_ENV")).
            SetType("access_key").
            // 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 value to imagesearch.cn-hangzhou.aliyuncs.com.
            SetEndpoint("imagesearch.cn-shanghai.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. 
            // SetEndpointType("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.
            // SetEndpoint("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 value to imagesearch-vpc.cn-hangzhou.aliyuncs.com.
            
            // Replace the value with the region in which your Image Search instance resides. For example, if your Image Search instance resides in the China (Hangzhou) region, set the value to cn-hangzhou.
            SetRegionId("cn-shanghai")
            // Create a client.
        client, err := imagesearch.NewClient(config)
        if err != nil {
            panic(err)
        }
        // Initialize runtimeObject.
        var runtimeObject = new(util.RuntimeOptions)
        b, err := os.Open("D:/123.jpg")
        if err != nil {
            panic(err)
        }
        request := new(imagesearch.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, obtain the instance name at https://imagesearch.console.aliyun.com/overview.
            SetInstanceName("XXXXXXXX").
            // Required. The name of the image. The name cannot exceed 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. 
            SetPicName("test").
            // Required. The ID of the product. The ID cannot exceed 512 characters in length. 
            // A product ID can correspond to multiple image names. 
            SetProductId("test").
            // The image. The image cannot exceed 4 MB in size. The transmission timeout period is 5 seconds. Only the following image formats are supported: PNG, JPG, JPEG, BMP, GIF, WebP, TIFF, and PPM.
            // For product, brand, and generic images, the length and the width of an image must range from 100 pixels to 4,096 pixels.
            // For cloth images, the length and the width of an image must range from 448 pixels to 4,096 pixels.
            // The image cannot contain rotation properties.
            SetPicContentObject(b).
            // Optional. The ID of the product category. 
            // 1. Product 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. Cloth, brand, and generic image searches: The category ID is set to 88888888 regardless of whether a category ID is specified. 
            SetCategoryId(2).
            // Optional. Specifies whether to recognize the subject in the image. Default value: true. 
            // 1. If you set this parameter to true, the system recognizes the subject in the image, and searches for images based on the recognized subject. The response includes the recognition result. 
            // 2. If you set this parameter to false, the system searches for images based on the entire image without subject recognition. 
            // 3. For cloth image searches, this parameter does not take effect. The system searches for images based on the entire image. 
            SetCrop(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. 
            // For cloth image searches, this parameter does not take effect. The system searches for images based on the entire image. 
            SetRegion("167,477,220,407").
            // 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. 
            SetCustomContent("this is a simple test!").
            // Optional. The attribute of the INT type. The attribute can be used to filter images in 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.
            SetIntAttr(100).
            // Optional. The attribute of the STRING type. The value cannot exceed 128 characters in length. The attribute can be used to filter images in image searches. If you specify this parameter, the response includes this parameter and its value. 
            SetStrAttr("1")
            // Call the method.
        resp, err := client.AddImageAdvance(request, runtimeObject)
        if err != nil {
            fmt.Println(err.Error())
        }
        fmt.Println(resp)
    }
  • Sample response

    {
       "RequestId": "B48CC953-F495-496C-BC96-B96826A860F1",
       "Success": true,
       "Message": "success",
       "Code": 0,
       "PicInfo": {
          "CategoryId": 2,
          "Region": "167,477,220,407"
       }
    }

SearchImageByPic

  • Sample code

    package main
    
    import (
        "fmt"
        "os"
        rpc "github.com/alibabacloud-go/darabonba-openapi/v2/client"
        imagesearch "github.com/alibabacloud-go/imagesearch-20201214/v4/client"
        util "github.com/alibabacloud-go/tea-utils/v2/service"
    )
    
    func main() {
        // Initialize config.
        // For information about how to create an AccessKey pair, visit 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 ID and AccessKey secret to a configuration file based on your business requirements. 
        var config = new(rpc.Config).SetAccessKeyId(os.Getenv("CC_AK_ENV")).
            SetAccessKeySecret(os.Getenv("CC_SK_ENV")).
            SetType("access_key").
            // 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 value to imagesearch.cn-hangzhou.aliyuncs.com.
            SetEndpoint("imagesearch.cn-shanghai.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. 
            // SetEndpointType("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.
            // SetEndpoint("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 value to imagesearch-vpc.cn-hangzhou.aliyuncs.com.
            
            // Replace the value with the region in which your Image Search instance resides. For example, if your Image Search instance resides in the China (Hangzhou) region, set the value to cn-hangzhou.
            SetRegionId("cn-shanghai")
            // Create a client.
        client, err := imagesearch.NewClient(config)
        if err != nil {
            panic(err)
        }
        // Initialize runtimeObject.
        var runtimeObject = new(util.RuntimeOptions)
        b, err := os.Open("D:/123.jpg")
        if err != nil {
            panic(err)
        }
        request := new(imagesearch.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, obtain the instance name at https://imagesearch.console.aliyun.com/overview.
            SetInstanceName("xxxxxxxxxx").
            // The image. The image cannot exceed 4 MB in size. The transmission timeout period is 5 seconds. Only the following image formats are supported: PNG, JPG, JPEG, BMP, GIF, WebP, TIFF, and PPM.
            // For product, brand, and generic images, the length and the width of an image must range from 100 pixels to 4,096 pixels.
            // For cloth images, the length and the width of an image must range from 448 pixels to 4,096 pixels.
            // The image cannot contain rotation properties.
            SetPicContentObject(b).
            // Optional. The ID of the product category. 
            // 1. Product 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. Cloth, brand, and generic image searches: The category ID is set to 88888888 regardless of whether a category ID is specified. 
            SetCategoryId(2).
            // Optional. The number of entries to be returned. Valid values: 1 to 100. Default value: 10. 
            SetNum(10).
            // Optional. The ordinal number of the first entry to be returned. Valid values: 0 to 499. Default value: 0.
            SetStart(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 results based on IntAttr: int_attr>=100.
            // 2. Filter results based on StrAttr: str_attr!="value1".
            // 3. Filter results based on int_attr and str_attr: int_attr=1000 AND str_attr="value1".
            SetFilter("int_attr=101 OR str_attr=\"2\"").
            // Optional. Specifies whether to recognize the subject in the image. Default value: true. 
            // 1. If you set this parameter to true, the system recognizes the subject in the image, and searches for images based on the recognized subject. The response includes the recognition result. 
            // 2. If you set this parameter to false, the system searches for images based on the entire image without subject recognition. 
            // 3. For cloth image searches, this parameter does not take effect. The system searches for images based on the entire image. 
            SetCrop(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. 
            // 3. For cloth image searches, this parameter does not take effect. The system searches for images based on the entire image. 
            SetRegion("167,476,220,407")
            // Call the method.
        resp, err := client.SearchImageByPicAdvance(request, runtimeObject)
        if err != nil {
            fmt.Println(err.Error())
        }
        fmt.Println(resp)
    }
  • Sample response

    {
       "RequestId": "F468F52E-963A-452B-88E7-1C43F92C9D81",
       "Success": true,
       "Code": 0,
       "Msg": "success",
       "Auctions": [
          {
             "CategoryId": 2,
             "ProductId": "php",
             "PicName": "test",
             "CustomContent": "this is a simple test!",
             "SortExprValues": "292.509948730469;16",
             "IntAttr": 100,
             "StrAttr": "1",
             "Score": 1
          }
       ],
       "Head": {
          "DocsReturn": 1,
          "DocsFound": 1,
          "SearchTime": 121
       },
       "PicInfo": {
          "CategoryId": 2,
          "Region": "167,476,220,407",
          "AllCategories": [
             {
                "Id": 0,
                "Name": "Tops"
             },
             .......
             {
                "Id": 88888888,
                "Name": "Other"
             }
          ],
          "MultiRegion": [
                {
                   "Region": "112,440,76,387"
                }
          ],
       }
    }

SearchImageByName

  • package main
    
    import (
        "fmt"
        "os"
        rpc "github.com/alibabacloud-go/darabonba-openapi/v2/client"
        imagesearch "github.com/alibabacloud-go/imagesearch-20201214/v4/client"
        util "github.com/alibabacloud-go/tea-utils/v2/service"
    )
    
    func main() {
        // Initialize config.
        // For information about how to create an AccessKey pair, visit 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 ID and AccessKey secret to a configuration file based on your business requirements. 
        var config = new(rpc.Config).SetAccessKeyId(os.Getenv("CC_AK_ENV")).
            SetAccessKeySecret(os.Getenv("CC_SK_ENV")).
            SetType("access_key").
            // 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 value to imagesearch.cn-hangzhou.aliyuncs.com.
            SetEndpoint("imagesearch.cn-shanghai.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. 
            // SetEndpointType("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.
            // SetEndpoint("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 value to imagesearch-vpc.cn-hangzhou.aliyuncs.com.
            
            // Replace the value with the region in which your Image Search instance resides. For example, if your Image Search instance resides in the China (Hangzhou) region, set the value to cn-hangzhou.
            SetRegionId("cn-shanghai")
            // Create a client.
        client, err := imagesearch.NewClient(config)
        if err != nil {
            panic(err)
        }
        request := new(imagesearch.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, obtain the instance name at https://imagesearch.console.aliyun.com/overview.
            SetInstanceName("XXXXXXXXXXX").
            // Required. The name of the image. The name cannot exceed 512 characters in length. 
            // An image is uniquely identified by the values of the ProductId and PicName parameters. 
            SetPicName("test").
            // Required. The ID of the product. The ID cannot exceed 512 characters in length. 
            // A product ID can correspond to multiple image names. 
            SetProductId("php").
            // Optional. The ID of the product category. 
            // 1. Product 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. Cloth, brand, and generic image searches: The category ID is set to 88888888 regardless of whether a category ID is specified. 
            SetCategoryId(2).
            // Optional. The number of entries to be returned. Valid values: 1 to 100. Default value: 10. 
            SetNum(10).
            // Optional. The ordinal number of the first entry to be returned. Valid values: 0 to 499. Default value: 0. 
            SetStart(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 results based on IntAttr: int_attr>=100.
            // 2. Filter results based on StrAttr: str_attr!="value1".
            // 3. Filter results based on int_attr and str_attr: int_attr=1000 AND str_attr="value1".
            SetFilter("str_attr=\"1\"") // Set a filter of the STRING type.
            // Call the method.
        resp, err := client.SearchImageByName(request)
        if err != nil {
            fmt.Println(err.Error())
        }
        fmt.Println(resp)
    }
  • Sample response

    {
       "RequestId": "9011A4A3-7642-44C5-AA33-6E38BA2EA3F1",
       "Success": true,
       "Code": 0,
       "Msg": "success",
       "Auctions": [
          {
             "CategoryId": 2,
             "ProductId": "php",
             "PicName": "test",
             "CustomContent": "this is a simple test!",
             "SortExprValues": "7.33136443711219e+24;0",
             "IntAttr": 100,
             "StrAttr": "1",
             "Score": 1
          }
       ],
       "Head": {
          "DocsReturn": 1,
          "DocsFound": 1,
          "SearchTime": 12
       },
       "PicInfo": {
          "CategoryId": 2,
          "Region": null,
          "AllCategories": [
             {
                "Id": 0,
                "Name": "Tops"
             },
            .......
             {
                "Id": 88888888,
                "Name": "Other"
             }
          ],
          "MultiRegion": [
                {
                   "Region": "112,440,76,387"
                }
           ],
          "Region": "383,681,291,549"
       }
    }

Delete

  • Sample code

    package main
    
    import (
        "fmt"
        "os"
        rpc "github.com/alibabacloud-go/darabonba-openapi/v2/client"
        imagesearch "github.com/alibabacloud-go/imagesearch-20201214/v4/client"
        util "github.com/alibabacloud-go/tea-utils/v2/service"
    )
    
    func main() {
        // Initialize config.
        // For information about how to create an AccessKey pair, visit 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 ID and AccessKey secret to a configuration file based on your business requirements. 
        var config = new(rpc.Config).SetAccessKeyId(os.Getenv("CC_AK_ENV")).
            SetAccessKeySecret(os.Getenv("CC_SK_ENV")).
            SetType("access_key").
            // 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 value to imagesearch.cn-hangzhou.aliyuncs.com.
            SetEndpoint("imagesearch.cn-shanghai.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. 
            // SetEndpointType("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.
            // SetEndpoint("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 value to imagesearch-vpc.cn-hangzhou.aliyuncs.com.
            
            // Replace the value with the region in which your Image Search instance resides. For example, if your Image Search instance resides in the China (Hangzhou) region, set the value to cn-hangzhou.
            SetRegionId("cn-shanghai")
            // Create a client.
        client, err := imagesearch.NewClient(config)
        if err != nil {
            panic(err)
        }
        request := new(imagesearch.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, obtain the instance name at https://imagesearch.console.aliyun.com/overview.
            SetInstanceName("XXXXXXXX").
            // Required. The name of the image. The name cannot exceed 512 characters in length. 
            // An image is uniquely identified by the values of the ProductId and PicName parameters. 
            SetPicName("test").
            // Optional. The name of the image. If you do not specify this parameter, the system deletes all the images that are related to the specified product ID. If you specify this parameter, the system deletes only the image that is specified by the ProductId and PicName parameters. 
            SetProductId("php")
            // Call the method.
        resp, err := client.DeleteImage(request)
        if err != nil {
            fmt.Println(err.Error())
        }
        fmt.Println(resp)
    }
  • Sample response

    {
       "RequestId": "C9432066-8918-447F-858B-B4B11E2A6941",
       "Success": true,
       "Message": "success",
       "Code": 0
    }

UpdateImage

  • Sample code

    package main
    
    import (
        "fmt"
        "os"
        rpc "github.com/alibabacloud-go/darabonba-openapi/v2/client"
        imagesearch "github.com/alibabacloud-go/imagesearch-20201214/v4/client"
        util "github.com/alibabacloud-go/tea-utils/v2/service"
    )
    
    func main() {
        // Initialize config.
        // For information about how to create an AccessKey pair, visit 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 ID and AccessKey secret to a configuration file based on your business requirements. 
        var config = new(rpc.Config).SetAccessKeyId(os.Getenv("CC_AK_ENV")).
            SetAccessKeySecret(os.Getenv("CC_SK_ENV")).
            SetType("access_key").
            // 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 value to imagesearch.cn-hangzhou.aliyuncs.com.
            SetEndpoint("imagesearch.cn-shanghai.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. 
            // SetEndpointType("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.
            // SetEndpoint("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 value to imagesearch-vpc.cn-hangzhou.aliyuncs.com.
            
            // Replace the value with the region in which your Image Search instance resides. For example, if your Image Search instance resides in the China (Hangzhou) region, set the value to cn-hangzhou.
            SetRegionId("cn-shanghai")
            // Create a client.
        client, err := imagesearch.NewClient(config)
        if err != nil {
            panic(err)
        }
        request := new(imagesearch.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, obtain the instance name at https://imagesearch.console.aliyun.com/overview.
            SetInstanceName("XXXXXXXX").
            // Required. The name of the image. The image name cannot be changed. 
            SetPicName("test").
            // Required. The ID of the product. The product ID cannot be changed. 
            SetProductId("php").
            // Optional. The attribute of the INT type. The attribute can be used to filter images in image searches. If you specify this parameter, the response includes this parameter and its value. 
            SetIntAttr(100).
            // Optional. The attribute of the STRING type. The value cannot exceed 128 characters in length. The attribute can be used to filter images in image searches. If you specify this parameter, the response includes this parameter and its value. 
            SetStrAttr("xxxx").        
            // Optional. The description that you want to add. The value cannot exceed 4,096 characters in length. 
            SetCustomContent("xxx")
            // Call the method.
        resp, err := client.UpdateImage(request)
        if err != nil {
            fmt.Println(err.Error())
        }
        fmt.Println(resp.Body)
    }
  • Sample response

    {
       "Code": 0,
       "RequestId": "63AB5A70-D314-13F9-AB28-0A7F03C7FC85",
       "Success": true
    }
                        

Detail

  • Sample code

    package main
    
    import (
        "fmt"
        "os"
        rpc "github.com/alibabacloud-go/darabonba-openapi/v2/client"
        imagesearch "github.com/alibabacloud-go/imagesearch-20201214/v4/client"
        util "github.com/alibabacloud-go/tea-utils/v2/service"
    )
    
    func main() {
        // Initialize config. 
        // For information about how to create an AccessKey pair, visit 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 ID and AccessKey secret to a configuration file based on your business requirements. 
        var config = new(rpc.Config).SetAccessKeyId(os.Getenv("CC_AK_ENV")).
            SetAccessKeySecret(os.Getenv("CC_SK_ENV")).
            SetType("access_key").
            // 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 value to imagesearch.cn-hangzhou.aliyuncs.com.
            SetEndpoint("imagesearch.cn-shanghai.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. 
            // SetEndpointType("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.
            // SetEndpoint("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 value to imagesearch-vpc.cn-hangzhou.aliyuncs.com.
            
            // Replace the value with the region in which your Image Search instance resides. For example, if your Image Search instance resides in the China (Hangzhou) region, set the value to cn-hangzhou.
            SetRegionId("cn-shanghai")
            // Create a client. 
        client, err := imagesearch.NewClient(config)
        if err != nil {
            panic(err)
        }
        request := new(imagesearch.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, obtain the instance name at https://imagesearch.console.aliyun.com/overview.
            SetInstanceName("XXXXXXXX")
            // Call the method. 
        resp, err := client.Detail(request)
        if err != nil {
            fmt.Println(err.Error())
        }
        fmt.Println(resp.Body)
    }
  • Sample response

    {
       "Instance": {
          "Capacity": 10,
          "Name": "xxxxx",
          "Qps": 1,
          "Region": "cn-shanghai",
          "ServiceType": 0,
          "TotalCount": 99999,
          "UtcCreate": "1620382716000",
          "UtcExpireTime": "1623081600000"
       },
       "RequestId": "13993EC0-C212-1BDC-8337-8D343A5510E6",
       "Success": true
    }
                        

DumpMeta

  • Sample code

    package main
    
    import (
        "fmt"
        "os"
        rpc "github.com/alibabacloud-go/darabonba-openapi/v2/client"
        imagesearch "github.com/alibabacloud-go/imagesearch-20201214/v4/client"
        util "github.com/alibabacloud-go/tea-utils/v2/service"
    )
    
    func main() {
        // Initialize config.
        // For information about how to create an AccessKey pair, visit 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 ID and AccessKey secret to a configuration file based on your business requirements. 
        var config = new(rpc.Config).SetAccessKeyId(os.Getenv("CC_AK_ENV")).
            SetAccessKeySecret(os.Getenv("CC_SK_ENV")).
            SetType("access_key").
            // 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 value to imagesearch.cn-hangzhou.aliyuncs.com.
            SetEndpoint("imagesearch.cn-shanghai.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. 
            // SetEndpointType("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.
            // SetEndpoint("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 value to imagesearch-vpc.cn-hangzhou.aliyuncs.com.
            
            // Replace the value with the region in which your Image Search instance resides. For example, if your Image Search instance resides in the China (Hangzhou) region, set the value to cn-hangzhou.
            SetRegionId("cn-shanghai")
            // Create a client.
        client, err := imagesearch.NewClient(config)
        if err != nil {
            panic(err)
        }
        request := new(imagesearch.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, obtain the instance name at https://imagesearch.console.aliyun.com/overview.
            SetInstanceName("XXXXXXXX")
            // Call the method. 
        resp, err := client.DumpMeta(request)
        if err != nil {
            fmt.Println(err.Error())
        }
        fmt.Println(resp.Body)
    }
  • Sample response

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

DumpMetaList

  • Sample code

    package main
    
    import (
        "fmt"
        "os"
        rpc "github.com/alibabacloud-go/darabonba-openapi/v2/client"
        imagesearch "github.com/alibabacloud-go/imagesearch-20201214/v4/client"
        util "github.com/alibabacloud-go/tea-utils/v2/service"
    )
    
    func main() {
        // Initialize config.
        // For information about how to create an AccessKey pair, visit 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 ID and AccessKey secret to a configuration file based on your business requirements. 
        var config = new(rpc.Config).SetAccessKeyId(os.Getenv("CC_AK_ENV")).
            SetAccessKeySecret(os.Getenv("CC_SK_ENV")).
            SetType("access_key").
            // 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 value to imagesearch.cn-hangzhou.aliyuncs.com.
            SetEndpoint("imagesearch.cn-shanghai.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. 
            // SetEndpointType("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.
            // SetEndpoint("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 value to imagesearch-vpc.cn-hangzhou.aliyuncs.com.
            
            // Replace the value with the region in which your Image Search instance resides. For example, if your Image Search instance resides in the China (Hangzhou) region, set the value to cn-hangzhou.
            SetRegionId("cn-shanghai")
            // Create a client.
        client, err := imagesearch.NewClient(config)
        if err != nil {
            panic(err)
        }
        request := new(imagesearch.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, obtain the instance name at https://imagesearch.console.aliyun.com/overview.
            SetInstanceName("XXXXXXXX").
            // Optional. The ID of the task. 
            SetId(1464).
            // Optional. The ordinal number of the first entry to be returned. Default value: 1. 
            SetPageNumber(1).
            // Optional. The number of entries to be returned. Default value: 20. 
            SetPageSize(1)
            // Call the method. 
        resp, err := client.DumpMetaList(request)
        if err != nil {
            fmt.Println(err.Error())
        }
        fmt.Println(resp.Body)
    }
  • Sample response

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

BatchTask

  • Sample code

    package main
    
    import (
        "fmt"
        "os"
        rpc "github.com/alibabacloud-go/darabonba-openapi/v2/client"
        imagesearch "github.com/alibabacloud-go/imagesearch-20201214/v4/client"
        util "github.com/alibabacloud-go/tea-utils/v2/service"
    )
    
    func main() {
        // Initialize config.
        // For information about how to create an AccessKey pair, visit 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 ID and AccessKey secret to a configuration file based on your business requirements. 
        var config = new(rpc.Config).SetAccessKeyId(os.Getenv("CC_AK_ENV")).
            SetAccessKeySecret(os.Getenv("CC_SK_ENV")).
            SetType("access_key").
            // 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 value to imagesearch.cn-hangzhou.aliyuncs.com.
            SetEndpoint("imagesearch.cn-shanghai.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. 
            // SetEndpointType("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.
            // SetEndpoint("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 value to imagesearch-vpc.cn-hangzhou.aliyuncs.com.
            
            // Replace the value with the region in which your Image Search instance resides. For example, if your Image Search instance resides in the China (Hangzhou) region, set the value to cn-hangzhou.
            SetRegionId("cn-shanghai")
            // Create a client.
        client, err := imagesearch.NewClient(config)
        if err != nil {
            panic(err)
        }
        request := new(imagesearch.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, obtain the instance name at https://imagesearch.console.aliyun.com/overview.
            SetInstanceName("XXXXXXXX").
            // Required. If images are stored in an Object Storage Service (OSS) bucket, enter the bucket name. 
            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 the "Perform batch operations" topic in the "User Guide" chapter of the Image Search documentation. 
            SetPath("/public/xxx").
            // Optional. The callback address if the call succeeds. The address must start with the string http:// or https://. 
            SetCallbackAddress("http://xxx/xxx")
            // Call the method. 
        resp, err := client.IncreaseInstance(request)
        if err != nil {
            fmt.Println(err.Error())
        }
        fmt.Println(resp.Body)
    }
  • Sample response

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

BatchTaskList

  • Sample code

    package main
    
    import (
        "fmt"
        "os"
        rpc "github.com/alibabacloud-go/darabonba-openapi/v2/client"
        imagesearch "github.com/alibabacloud-go/imagesearch-20201214/v4/client"
        util "github.com/alibabacloud-go/tea-utils/v2/service"
    )
    
    func main() {
        // Initialize config.
        // For information about how to create an AccessKey pair, visit 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 ID and AccessKey secret to a configuration file based on your business requirements. 
        var config = new(rpc.Config).SetAccessKeyId(os.Getenv("CC_AK_ENV")).
            SetAccessKeySecret(os.Getenv("CC_SK_ENV")).
            SetType("access_key").
            // 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 value to imagesearch.cn-hangzhou.aliyuncs.com.
            SetEndpoint("imagesearch.cn-shanghai.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. 
            // SetEndpointType("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.
            // SetEndpoint("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 value to imagesearch-vpc.cn-hangzhou.aliyuncs.com.
            
            // Replace the value with the region in which your Image Search instance resides. For example, if your Image Search instance resides in the China (Hangzhou) region, set the value to cn-hangzhou.
            SetRegionId("cn-shanghai")
            // Create a client.
        client, err := imagesearch.NewClient(config)
        if err != nil {
            panic(err)
        }
        request := new(imagesearch.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, obtain the instance name at https://imagesearch.console.aliyun.com/overview.
            SetInstanceName("XXXXXXXX").
            // Optional. The ID of the batch task. 
            SetId(1470).
            // Optional. The name of the OSS bucket. 
            SetBucketName("bucketName").
            // Optional. The path to the OSS bucket. 
            SetPath("xx").
            // Optional. The ordinal number of the first entry to be returned. Default value: 1. 
            SetPageNumber(1).
            // Optional. The number of entries to be returned. Default value: 20. 
            SetPageSize(1)
            // Call the method. 
        resp, err := client.DumpMetaList(request)
        if err != nil {
            fmt.Println(err.Error())
        }
        fmt.Println(resp.Body)
    }
  • Sample response

    {
       "Data": {
          "Increments": {
             "Instance": [
                {
                   "BucketName": "xxxx",
                   "Code": "0",
                   "ErrorUrl": "https://xxTqoxxres=16706x\u0xM%3D",
                   "Id": 1470,
                   "Msg": "success",
                   "Path": "/x/x",
                   "Status": "NORMAL",
                   "UtcCreate": "1639107872000",
                   "UtcModified": 1639125540000
                }
             ]
          },
          "PageNumber": 1,
          "PageSize": 1,
          "TotalCount": 1
       },
       "RequestId": "75D08E30-0161-158F-806A-A6C4C2CE04FC"
    }