0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Linode Object Storage のファイルを検索する方法

Posted at

この記事では Linode のオブジェクトストレージ内のファイルを検索する方法を紹介します。
ユースケースとしてはファイルの有無や最終更新日時の確認です。

Object Storage の GUI で不便なところ

Object Storage のポータルにはファイルの一覧を確認できる機能があります。
しかし、ここでは Path やファイル名での検索ができません。
ファイル数が多い場合は探しているファイルが出てくるまでスクロールし続ける必要があります。

linode-portal-objectstorage.jpg

これではいくら時間があっても足りません。
そこで今回は API を利用して対象のファイルの情報を取得していきます。

API Token の発行

以下の記事をもとに API Token を取得してください
Linode ポータルからトークンを取得する

API を呼び出す

以下の API ドキュメントをもとに API を呼び出します。

List Object Storage bucket contents

まずは API で対象の Bucket のファイル情報を取得できるか確認してみましょう。

慣れていない方は上記のドキュメント内で自身の Bucket 情報や Credential (API Token)を入力することで、リクエストに利用する curl コマンドを生成してくれます。

regionId は以下のページでも確認できます。
Supported endpoint types by region

objectstorage-path-params.png

objectstorage-credential-curl-request.png

curl --request GET \
     --url 'https://api.linode.com/v4/object-storage/buckets/jp-osa-1/example-bucket/object-list?page_size=100' \
     --header 'accept: application/json' \
     --header "authorization: Bearer 3c21934ef3fefd4jkf04e79174c3352370633d7aa4c78635d4d3647d6e7c2xg" \
| jq

{
  "data": [
    {
      "name": "path/to/example_1.jpg",
      "size": 1022382,
      "last_modified": "2023-10-02T05:39:25.243Z",
      "etag": "d105471fe628c27771782b0c4b21fcwd",
      "owner": "08e3ff2c-7654-4457-848d-cb9d733tdssw"
    },
    {
      "name": "path/to/example_2.jpg",
      "size": 325302,
      "last_modified": "2023-07-20T02:37:36.741Z",
      "etag": "d41d8cd98f00b204e9800998ecfedcgd",
      "owner": "08e3ff2c-7654-4457-848d-cb9d733tdssw"
    },

[output omitted]

  ],
  "next_marker": null,
  "is_truncated": false
}

今回は JSON の出力を見やすくするためにコマンドの末尾に jq をつけています。

情報が取得できることを確認したら次は Path で検索していきます。

Path でフィルターする

API リクエストに prefix というパラメータを付与することで、Bucket 内の特定ファイルの情報のみを取得できます。

prefix での検索は前方一致のため、path を含めて入力する必要があります。
前方一致のため、path/to/example_1.jpg というファイルを検索する場合は path/to/example_ のような形式でも検索できます。

API ドキュメントの QUERY PARAMS という項目に prefix がありますので、そこに検索したいファイルを Path を含めて記載してください。

objectstorage-query-params.png

Path の最初の / は不要です

入力すると prefix がクエリパラメータに含まれた curl コマンドが生成されます。

curl --request GET \
     --url 'https://api.linode.com/v4/object-storage/buckets/jp-osa-1/example-bucket/object-list?prefix=path%2Fto%2Fexample_1.jpg&page_size=100' \
     --header 'accept: application/json' \
     --header "authorization: Bearer 3c21934ef3fefd4jkf04e79174c3352370633d7aa4c78635d4d3647d6e7c2xg" \
| jq

{
  "data": [
    {
      "name": "path/to/example_1.jpg",
      "size": 1022382,
      "last_modified": "2023-10-02T05:39:25.243Z",
      "etag": "d105471fe628c27771782b0c4b21fcwd",
      "owner": "08e3ff2c-7654-4457-848d-cb9d733tdssw"
    }
  ],
  "next_marker": null,
  "is_truncated": false
}

この方法で特定のファイルの情報のみを取得できます。

まとめ

Akamai はCDN、セキュリティ、クラウドサービスを通じ、オンラインライフの力となり守っています。本稿でご紹介したような課題やご相談があれば、お気軽にお問い合わせください。

関連記事

アカマイ・テクノロジーズ合同会社の Qiita では、 Akamai Connected Cloud 関連などの開発者向けの記事を掲載しております。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?