edit-icon download-icon

OSS import

Last Updated: Jan 22, 2019

Scenario

The OSS Import method is suitable for scenarios where you have to import a large volume of images.

Procedure

To use OSS Import, you must activate the Object Storage Service (OSS) and then authorize the required RAM role to your Image Search account as following:

Activate OSS

  • For information about activating the OSS service, see Sign up for OSS. Make sure your Image Search instances and OSS are in the same region.
  • After the OSS service is activated, you must create a bucket. For more information, see Create a bucket.

Import images

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

  • The path where the images are stored is configurable. 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 only one image.
    • All image information is encoded in JSON format as follows:
Name Type Description Remarks
operator String Action This field specifies the action to be taken on the images. ADD means adding new images.

DELETE means removing images.
item_id String Unique product/image identifier For product search, this field specifies the product ID.

For generic search, this field specifies the image name.
cat_id Integer Category information For product search, this field is not required, it specifies the category to which the images belong. For more information, see Category Reference.

This field is not required by generic search. You can leave this field empty or set the value 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 image names that you need 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.

For more information about importing images to OSS, see Upload objects.

Authorize RAM roles to your account

To use OSS Import, you must use Security Token Service to grant your Image Search account temporary permissions to access OSS. The procedure is as follows:

Create a role

  1. Go to the RAM console, select Role Roles > Create RAM Role.

    image.png | center | 802x390
  2. Select Alibaba Cloud Service > Image Search.

    image.png | center | 802x595

  3. Enter a RAM role name.

    image.png | center | 802x407

Create a policy

A newly created role does not have any permissions. You must create a policy to acquire the relevant permissions.

To create a policy, use the following format:

  1. {
  2. "Version": "1",
  3. "Statement": [
  4. {
  5. "Effect": "Allow",
  6. "Action": [
  7. "oss:GetObject"
  8. ],
  9. "Resource": [
  10. "acs:oss:*:*:${bucket}${path}/*"
  11. ]
  12. }
  13. ]
  14. }
  • ${bucket}: Specifies a bucket.
  • ${path}: Specifies a path for storing the images that you need to import.

Example

In this example, a policy is created for importing images to the /increment path in the bucket named imagesearch-increment.

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

Authorize the RAM role to your account

To authorize the RAM role to your account, follow these steps:

  1. On the RAM console, select Policies > Create Policy.

    image.png | center | 830x405

  2. Enter the Policy Name and Policy Document and then click OK.

    image.png | center | 830x639

  3. Return to the RAM console, select RAM Roles, and select your role from the list.

    image.png | center | 830x405

  4. Click Add Permissions, select your policy in the dialog box that appears, and click OK.

    image.png | center | 830x405

Import images

To import images from OSS, go to the Image Search console, on Instance Details page, click OSS Import, enter the basic information, and then click Import.

image.png | center | 830x404

ARN: Your RAM role account name created for importing to Image Search. Click your role to view the ARN, as shown in the following figure:

image.png | center | 830x406

Bucket Name: The name of the bucket that stores your images in OSS.

Note: Make sure your Image Search instance and OSS are in the same region.

Path: The path where your images are stored.

Note: The data path must start with a forward slash (/), for example, /imagesearch.

The following figure shows the data path of /imagesearch in the imagesearch1 bucket:

image.png | center | 830x406

OSS import history

On the Instance Details page, you can click View History to view the history of OSS import tasks. When the OSS import task is complete, you receive a message that indicates the result.

  • If some of the images cannot be processed, you receive the following error message: “Some of the images cannot be imported. Download Report.” If this error occurs, you can download the report to view the impacted images and identify the root cause of the error.
  • If all of the selected images have been imported, you receive a message indicating that the import task is successful.
Thank you! We've received your feedback.