edit-icon download-icon

OSS Import

Last Updated: Aug 01, 2018

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 OSS service and then authorize the required RAM role to your Image Search account as following:

Activate OSS Service

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

Import Images

When you import images to the bucket, follow these guidelines:

  • The path where the images are stored is configurable. After you specify a path, click OSS Import to import the 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 will be 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 the RAM Role 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 RAM Console, select Role Management > Create Role.

    image.png | center | 802x390
  2. Select Services > Image Search.

    image.png | center | 802x398image.png | center | 802x595

  3. Configure basic role information.

    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 RAM console, select Policies > Create Authorization Policy.

    image.png | center | 830x405

  2. Select Blank Template.

    image.png | center | 830x534

  3. Enter the Authorization Policy Name and Policy Content and then click Create Policy.

    image.png | center | 830x639

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

    image.png | center | 830x405

  5. Select Role Authorization Policies, click Edit Authorization Policy, 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, click OSS Import on the Instance List page or the Instance Details page, enter the basic information, and click Import. Image Search will read data from OSS.

image.png | center | 830x404

ARN: ARN of the role that you created in the Permit Image Search to access OSS step. Click your role to view the ARN, as shown in the following figure:

image.png | center | 830x406

Bucket: 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.

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