Updated on 2024-09-29 GMT+08:00

Using obsutil

obsutil is a command line tool. If you are familiar with the command line interface (CLI), obsutil is a good choice in batch processing and automatic tasks.

The following describes how to use basic OBS functions with obsutil in Linux, including creating a bucket (bucket-test as an example), uploading an object, as well as downloading and sharing the object.

Preparations

Before using obsutil, you must create a HUAWEI ID, complete real-name authentication, and top up your account. Then, you need to install obsutil and obtain the access keys.

  1. Sign up for a HUAWEI ID and complete real-name authentication.

    If you already have a HUAWEI ID, skip this step. Otherwise, do as follows:

    1. Sign up for a HUAWEI ID and enable Huawei Cloud services.
    2. Complete real-name authentication by referring to Individual Real-Name Authentication or .

  2. Top up your account by referring to Topping Up an Account.

    Make sure your account balance is sufficient, so that you can properly use OBS and other related resources.

  3. Download and install obsutil by referring to Downloading and Installing obsutil.
  4. Obtain the access keys by referring to Access Keys.

Creating a Bucket

Create a bucket (bucket-test as an example, which is user-defined and must be unique) in the CN-Hong Kong region:

./obsutil mb obs://bucket-test -location=ap-southeast-1

If the command output is as follows, the bucket is created.
Create bucket [bucket-test] successfully, request id [00000190CA0531DE4015FE3458C7B4C0]

Uploading an Object

Upload the local test.txt file to bucket bucket-test:

./obsutil cp /temp/test.txt obs://bucket-test/test.txt

If the command output is as follows, the file is uploaded.
Parallel:      5                   Jobs:          5
Threshold:     52428800            PartSize:      5242880
VerifyLength:  false               VerifyMd5:     false
CheckpointDir: /root/.obsutil_checkpoint

test.txt:[j1] [==============================================] 100.00% 48.47 KB/s 0s
Upload successfully, 4.44KB, /temp/test.txt --> obs://bucket-test1/test.txt

Downloading an Object

Download the test.txt object from bucket bucket-test to your local PC:

./obsutil cp obs://bucket-test/test.txt /temp/test1.txt

If the command output is as follows, the object is downloaded.
Parallel:      5                   Jobs:          5
Threshold:     52428800            PartSize:      5242880
VerifyLength:  false               VerifyMd5:     false
CheckpointDir: /root/.obsutil_checkpoint

test.txt:[=============================================] 100.00% 775.52 KB/s 0s
Download successfully, 4.44KB, obs://bucket-test1/test.txt --> /temp/test1.txt

Sharing an Object

  1. Create a download URL for the object:

    obsutil sign obs://bucket-test/test.txt

    If the command output is as follows, the download URL is created.
    Download url of [obs://bucket-test/test.txt] is:
      http://bucket-test.obs.ap-southeast-1.myhuaweicloud.com/bucket-test/test.txt?AccessKeyId=xxxx&Expires=1552548758&Signature=xxxx

  2. Copy and share the URL with others. Then, they can use this URL to access the object in a browser.

    Accessing an object in a browser will make the object forcibly downloaded. If you want people to preview the object you shared, see How Do I Preview OBS Objects in My Web Browser?

Related Information

In addition to the operations mentioned above, the following advanced obsutil functions are available for you to use.

  • Bucket policies: obsutil provides bucket policies to enable fine-grained access control over buckets and objects.