APIドキュメント
リストバケット
このセクションのサンプルでは、IDrive® e2 ストレージ内のすべてのバケットのリストを返す方法を説明します。以下はIDrive®e2 のChicagoリージョンの例です。
以下の操作を行う前に、必要な設定手順に従って ください。
以下のコマンドを使って、ストレージ内のすべてのバケットをリストアップします。
aws s3api list-buckets --endpoint-url https://storageendpoint
バケツのリストを表示するには、以下のコードに従ってください。
#!/bin/python インポートboto3 # IDrive e2用のS3クライアントを作成する。 endpoint = "l4g4.ch11.idrivee2-2.com" クライアント = boto3.client("s3", endpoint_url=endpoint) # バケットのリストを取得 response = client.list_buckets() # バケツ名を表示 for bucket in response["Buckets"]: print(bucket["Name"])
const AWS = require('aws-sdk'); // Create an S3 client for IDrive e2 const s3 = new AWS.S3({ endpoint: "https://xyz1.ch11.idrivee2-2.com", //your storage-endpoint accessKeyId: process.env.access_key, //your access-key secretAccessKey: process.env.secret_key, //your secret-key }); // list buckets call s3.listBuckets(function(err, data) { if (err) { console.log("Error:", err); } else { console.log("Success:", data); } });
以下のコードに従って、IDrive® e2 ストレージ内のすべてのバケットをリストアップしてください。以下は Composer によるインストール方法の例です。その他の方法については、 PHP の使用方法に従って以下のコードの"require"ステートメントを変更してください。
<?php require "vendor/autoload.php"; use Aws\S3\S3Client; use Aws\Exception\AwsException; // Create an S3 client for IDrive e2 $profile_credentials = [ "profile" => "default", "endpoint" => "l4g4.ch11.idrivee2-2.com", "region" => "Chicago", "version" => "latest", "use_path_style_endpoint" => true, ]; $s3 = S3Client::factory($profile_credentials); // Get list of buckets try { $buckets = $s3->listBuckets(); // print bucket names foreach ($buckets["Buckets"] as $bucket) { echo "{$bucket["Name"]}\n"; } } catch (AwsException $e) { echo "Error: {$e->getMessage()}" . PHP_EOL; }
以下のコードに従って、IDrive® e2 ストレージ内のすべてのバケットをリストアップしてください。
require 'aws-sdk-s3' # Create an S3 client for IDrive e2 endpoint = 'l4g4.ch11.idrivee2-2.com' client = Aws::S3::Client.new(region: 'Chicago', endpoint: endpoint) # List buckets call begin puts "Success: #{client.list_buckets}" rescue StandardError => ex puts "Error: #{ex}" end