All Products
Document Center

Upload images

Last Updated: Jun 28, 2020

This topic describes how to upload images to Alibaba Cloud Image Search.

Image upload methods

Image Search allows you to upload images by calling API actions or by using OSSImport:

  • If you want to upload a small number of images and you are not using Image Search for enterprise applications, we recommend that you use Image Search API actions. For how to upload images by using API actions, see Add an image. If you choose this method, you can skip the rest of this topic.
  • If you want to upload a large number of images, or you are an enterprise user, we recommend that you upload images by using the OSSImport tool. For detailed steps, see the following procedure.

Introduction to the OSSImport tool

OSSImport is a tool provided by Alibaba Cloud Object Storage Service (OSS) to migrate data to OSS buckets. You can deploy OSSImport on your local server or your Elastic Compute Service (ECS) instances.

The advantages of uploading images by using OSSImport are as follows:

  • Images can be updated to Image Search in real time.
  • Different projects, such as development projects and online projects can share the same OSS bucket.
  • Each service unit can upload and update images according to their own OSSImport metadata files.
  • A large number of images can be uploaded at a time and used in different scenarios, which makes full use of the network bandwidth.

Upload images by using the OSSImport tool


  • The size of each image to be uploaded does not exceed 2 MB.
  • Both the height and width of each image are in the range of 200 pixels to 1024 pixels.


  1. Download the OSSImport tool.

    You can download the tool in either standalone mode or distributed mode:

    • Standalone mode is recommended for small-scale data migration scenarios where the total data size is smaller than 30 TB. Download OSSImport for standalone mode.
    • Distributed mode is recommended for large-scale data migration scenarios. You can deploy OSSImport on one or more machines that can access OSS. Download OSSImport for distributed mode.

      When you migrate data on a large scale, we recommend that you deploy OSSImport on an ECS instance that is in the same region of OSS, and mount the server where the source data is stored to Alibaba Cloud Virtual Private Cloud (VPC) by using private lines. You can improve the efficiency by migrating data from multiple ECS instances to OSS over the Internet.

  2. Sign up for OSS.

  3. Create an OSS bucket. The bucket must be in the same region as the Image Search instance you want to upload images to. For more information, see Create a bucket.

  4. Import images.

    To import images to an OSS bucket, follow these guidelines:

  • The path where the images are stored can be customized. After you specify a path, click OSS Import to import images.

  • Make sure that you have created the increment.meta file in the specified path. This file is used to store information about OSS import tasks. The file format must meet the following requirements:
    • Each row corresponds to only one image.
    • Information about each image is encoded in JSON format, as described in the following table.

Field Type Description Remarks
OperationType String Action This field specifies the action to be taken.

ADD: adds a product or an image

DELETE: deletes a product or an image
ProductId String Unique identifier of a product or an image For a product search, this field specifies the product ID.

For a generic search, this field specifies the image name.
CategoryId Integer Category information For a product search, you can leave this field unspecified, or set a value according to the category reference.

For a generic search, you can leave this field unspecified, or set this field to 88888888.
CustomContent String Custom content This field specifies the custom content, which is read-only to the system and is displayed in the search results.
PicName String Image list This field specifies a list of names of images that you want to import.

  • Example of the increment.meta file:

    1. {"OperationType":"ADD","ProductId":"1000", "CategoryId":0, "CustomContent":"k1:v1,k2:v2,k3:v3","PicName":"girl_cloth1.jpg"}
    2. {"OperationType":"ADD","ProductId":"1001", "CategoryId":1,"CustomContent":"k1:v1,k2:v2,k3:v3", "PicName":"girl_cloth3.jpg"}
    3. {"OperationType":"ADD","ProductId":"1002", "CategoryId":0, "CustomContent":"k1:v1,k2:v2,k3:v3", "PicName":"girl_cloth4.jpg"}
    4. {"OperationType":"ADD","ProductId":"1003", "CustomContent":"k1:v1,k2:v2,k3:v3", "PicName":"girl_cloth6.jpg"}
    5. {"OperationType":"DELETE","ProductId":"1004", "PicName":"fengyi.jpg"}
    6. {"OperationType":"DELETE","ProductId":"1005"}
  • All images listed in the increment.meta file are stored in the same path as the increment.meta file.

5. Create a RAM role:

a) Log on to the RAM console.

b) In the left-side navigation pane, click RAM Roles.

c) Click Create RAM Role.


d) Select Alibaba Cloud Service and click Next.


e) Enter a RAM role name, select Image Search from the Select Trusted Service drop-down list, and click OK.


6. Create a policy.

By default, a newly created role does not have any permissions. You must create a policy to grant relevant permissions to the role. For example, you can create a policy for importing images to the /increment path in the bucket named imagesearch-increment as follows:

  1. {
  2. "Version": "1",
  3. "Statement": [
  4. {
  5. "Effect": "Allow",
  6. "Action": [
  7. "oss:GetObject"
  8. ],
  9. "Resource": [
  10. "acs:oss:*:*:imagesearch-increment/increment/*"
  11. ]
  12. }
  13. ]
  14. }

7. Attach the policy to the RAM role:

a) Log on to the RAM console.

b) In the left-side navigation pane, click Policies.

c) Click Create Policy.


d) Enter a policy name, set Configuration Mode to Script, paste the policy document you created in step 6, and click OK.


e) Go back to the RAM console.

f) On the RAM Roles page, find the RAM role you created before, and click Add Permissions.


g) Select Custom Policy from the drop-down list.

h) In the Policy Name column, click the name of the target policy and click OK.


8. Go to the RAM Roles page and click the name of the role. Then, find the ARN in the Basic Information section.


9. Import images from OSS:

a) Activate Image Search and create an instance.

b) On the Generic Search Instances page, choose More > Import, enter the required information, and then click Import.


c) Check the import status by clicking the instance ID in the Image Search console.


If the import status is Failed, click Show Import History to obtain the details. For more information, see What might cause an OSS import request failure?


10. Test the service in the Image Search console.

After images are successfully uploaded, you can click the instance ID and then click Test Service to perform a test.