All Products
Search
Document Center

Upload images

Last Updated: Jul 12, 2019

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

Prerequisites

  • 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.

Procedure

  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
operator String Action This field specifies the action to be taken.

ADD: adds a product or an image

DELETE: deletes a product or an image
item_id 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.
cat_id 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.
cust_content String Custom content This field specifies the custom content, which is read-only to the system and is displayed in the search results.
pic_list Array Image list This field specifies a list of names of images that you want to import.

  • Example of the increment.meta file:

    1. {"operator":"ADD","item_id":"1000", "cat_id":0, "cust_content":"k1:v1,k2:v2,k3:v3", "pic_list":["girl_cloth1.jpg"]}
    2. {"operator":"ADD","item_id":"1001", "cat_id":0, "cust_content":"k1:v1,k2:v2,k3:v3", "pic_list":["girl_cloth2.jpg"]}
    3. {"operator":"ADD","item_id":"1002", "cat_id":0, "cust_content":"k1:v1,k2:v2,k3:v3", "pic_list":["girl_cloth3.jpg"]}
    4. {"operator":"ADD","item_id":"1003", "cat_id":0, "cust_content":"k1:v1,k2:v2,k3:v3", "pic_list":["girl_cloth4.jpg"]}
    5. {"operator":"DELETE","item_id":"10005", "pic_list":["fengyi.jpg"]}
    6. {"operator":"DELETE","item_id":"10006"}
  • 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.

1

d) Select Alibaba Cloud Service and click Next.

2

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

3


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.

4

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

5

e) Go back to the RAM console.

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

6

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.

7


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

8


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.

9

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

10

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?

11


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.

12