This topic describes how to add and delete images in batches.

Background information

After you connect Image Search to Alibaba Cloud Object Storage Service (OSS), you can use the batch operation feature of Image Search to import images from OSS to Image Search or delete images from Image Search in batches. This method applies to scenarios where you need to manage large-scale images by using a task. The batch operation feature provides benefits such as high stability, high efficiency, and ease of use. If you need to add or delete a large number of images, we recommend that you perform batch operations.

Procedure of performing batch operations

  1. Activate OSS.
  2. Import images to OSS.
  3. Create the increment.meta file.
  4. Authorize an Image Search user to access OSS.
  5. Create a batch task in the Image Search console.

Activate OSS

If OSS is not activated, activate OSS. For more information about how to activate OSS, see Activate OSS. After you activate OSS, you must create buckets. For more information, see Create buckets.
  • You are charged for OSS separately. For more information about the billing methods, see Overview.
  • You must ensure that your OSS and Image Search instances reside in the same region. Otherwise, the batch operation feature is unavailable.

Import images to OSS

Import images to OSS.

For more information about how to import images, see Upload objects.
Note You can specify a path to store the images that are imported to OSS. When you create a batch task, you must enter this path.

Create the increment.meta file

Create the increment.meta file in the path where the images are stored in OSS. This file is used to store information about batch tasks.
Note The increment.meta file and the images that are involved in the increment.meta file must be stored in the same path. Otherwise, batch operations fail.
The following example of the increment.meta file is provided for your reference:
{"OperationType": "ADD","ProductId": "1000","PicName": "girl_cloth1.jpg","CategoryId": 0,"IntAttr": 0,"StrAttr": "value1","CustomContent": "k1:v1,k2:v2,k3:v3","Region": "20,40,60,80"}
{"OperationType": "ADD","ProductId": "1000","PicName": "girl_cloth2.jpg","CategoryId": 0,"IntAttr": 0,"StrAttr": "value2","CustomContent": "k1:v1,k2:v2,k3:v3","Region": "20,40,60,80"}
{"OperationType": "ADD","ProductId": "1001","PicName": "girl_cloth3.jpg","CategoryId": 1,"CustomContent": "k1:v1,k2:v2,k3:v3"}
{"OperationType": "ADD","ProductId": "1002","PicName": "girl_cloth4.jpg","CategoryId": 0,"CustomContent": "k1:v1,k2:v2,k3:v3","Crop": false}
{"OperationType": "ADD","ProductId": "1003","PicName": "girl_cloth7.jpg","CustomContent": ""}
{"OperationType": "ADD","ProductId": "1003","PicName": "girl_cloth6.jpg","CustomContent": "k1:v1,k2:v2,k3:v3"}
{"OperationType": "DELETE","ProductId": "1004","PicName": "fengyi.jpg"}
{"OperationType": "DELETE","ProductId": "1005"}
In this file, information about each image is encoded in JSON format. The following table describes the parameters in the file.
Parameter Type Required Description
OperationType String Yes The type of the operation. Valid values:
  • ADD: Add images.
  • DELETE: Delete images.
ProductId String Yes The unique ID of the image.
PicName String Yes The name of the image. The name of the image that is stored in the OSS bucket.
Note Each row contains at most one image name. If one image ID corresponds to multiple image names, you must write multiple rows.
CategoryId Integer No The category of the image. For more information, see Category reference.
  • For product image searches, if you specify a category for an image, the specified category prevails. The specified category must be within the category reference scope. Otherwise, the image fails to be imported to the image gallery in Image Search. If you do not specify a category for an image, the system predicts the category, and returns the result of category prediction in the response.
  • For generic image searches, the system sets the category ID to 88888888, regardless of whether you specify a category for an image.
CustomContent String Yes The user-defined content. The value can be up to 4,096 characters in length.
IntAttr Integer No The integer attribute. The attribute can be used to filter images when you search for images.
StrAttr String No The string attribute. The value can be up to 128 characters in length. The attribute can be used to filter images when you search for images.
Crop Boolean No Specifies whether to recognize the subject in the image and search for images based on the recognized subject. Valid values: true and false. Default value: true.
  • true: The system recognizes the subject in the image and searches for images based on the recognized subject.
  • false: The system does not recognize the subject in the image, and searches for images based on the entire image.
Region String No The subject area in the image. The subject area is in the format of x1,x2,y1,y2. x1 and y1 represent the upper-left corner pixel. x2 and y2 represent the lower-right pixel.
Note If you specify this parameter, the Crop parameter does not take effect.

Authorize an Image Search account to access OSS

Image Search provides the batch operation feature based on OSS. You must use Security Token Service (STS) to grant your Image Search account permissions to access OSS.

  1. Create a RAM role.
    1. Log on to the RAM console.
    2. In the left-side navigation pane, choose RAM Roles > Create RAM Role.
      Batch operation - Create RAM Role
    3. In the Create RAM Role pane, select Alibaba Cloud Service for the Trusted entity type parameter, and then click Next.
      Batch operation - Alibaba Cloud Service
    4. Configure role information.
      • Role Type: Select Normal Service Role.
      • RAM Role Name: Enter a RAM role name. The role name is imagesearch-test in this example.
      • Select Trusted Service: Select Image Search from the drop-down list.
      Batch operation - Create RAM Role
  2. Create a policy.
    1. In the left-side navigation pane, choose Permissions > Policies.
    2. On the Policies page, click Create Policy.
      Batch operation - Create Policy
    3. Edit the policy content.
      • Enter a policy name.
      • Set the Configuration Mode parameter to Script. In the following example, the policy content is provided.
          "Version": "1",
          "Statement": [
              "Effect": "Allow",
              "Action": [
              "Resource": [
        • ${bucket}: the bucket that you create in OSS to store your images, for example, imagesearch-increment
        • ${path}: the path where your increment.meta file is stored, for example, /increment
      Batch operation - Create Policy
  3. Grant permissions.
    1. In the left-side navigation pane of the RAM console, click RAM Roles.
    2. Click the name of the RAM role that you create.
      Grant permissions
    3. On the Permissions tab, click Add Permissions.
      Add permissions
    4. In the Add Permissions pane, click Custom Policy and select the policy that you create.
      Batch operation - Grant permissions
    5. Go back to the Permissions tab. You can view the custom policy that is attached to the RAM role.
      View the custom policy

Create a batch task

  1. Log on to the Image Search console.
  2. Select the service type and click the name of your instance.
  3. Click the Batch Operation tab.
    Batch Operation
  4. Click Create Batch Task.
    Create Batch Task
  5. Specify the following parameters for the batch task:
    • ARN
      The following figure shows the location where you can view the value of the ARN parameter.Batch Operation - ARN
    • Bucket Name
      This parameter specifies the name of the bucket that you create in OSS.
      Note Make sure that your OSS instance and Image Search instance reside in the same region.
    • Path
      This parameter specifies the path where the images to be uploaded and the increment.meta file are stored.
      Note The path must start with a forward slash (/), for example, /imagesearch.
      Batch Operation - Path

What to do next

On the Instance Details page of the selected instance, you can view information about all the batch tasks on the Batch Operation tab. If batch tasks are in the Success state, you can view the following prompts in the Error Message column.View the result of the batch task
  • The message "Some of the images cannot be imported. Click Download" indicates that some images fail to be imported. You can download the file to view failure causes.
  • The message "Success" indicates that all the images are imported.