Object Storage Service (OSS) は、従来のファイルシステムで使用される階層構造ではなく、フラット構造を使用してオブジェクトを格納します。 OSS のすべてのデータは、バケット内のオブジェクトとして格納されます。 オブジェクト管理を容易にするため、OSS コンソールには、名前がスラッシュ (/) で終わるオブジェクトがディレクトリとして表示されます。 ディレクトリは、ファイルシステムのフォルダに似ています。 ディレクトリを使用すると、オブジェクトを階層的に整理およびグループ化し、アクセス制御を容易にすることができます。
動作原理
OSS は、フォルダのような構造をサポートするために、ゼロバイトオブジェクトを使用してディレクトリをシミュレートします。 OSS でディレクトリを作成する場合、ディレクトリの名前を指定します。 たとえば、バケットに log という名前のディレクトリを作成すると、OSS は log/ という名前のゼロバイトオブジェクトを作成します。
ディレクトリの例
OSS は、名前がスラッシュ (/) で終わるオブジェクトをディレクトリとして扱います。 次の例は、examplebucket という名前のバケットの構造を示しています。
examplebucket
└── log/
├── date1.txt
├── date2.txt
├── date3.txt
└── destfolder/
└── 2021/
├── photo.jpg
上記の構造では、次のとおりです。
次の 3 つのオブジェクトの名前には、"log" というプレフィックスが付いています: log/date1.txt、log/date2.txt、log/date3.txt。 OSS コンソールには、log という名前のディレクトリが表示されます。 date1.txt、date2.txt、date3.txt という名前の 3 つのオブジェクトがディレクトリに格納されます。
次のオブジェクトの名前には、"destfolder" というプレフィックスが含まれています: destfolder/2021/photo.jpg。 OSS コンソールには、destfolder という名前のディレクトリが表示されます。 ディレクトリには、2021 という名前のサブディレクトリが含まれています。 photo.jpg という名前のオブジェクトがサブディレクトリに格納されます。
ディレクトリへのアクセスを承認する
次の例は、前のセクションで説明した examplebucket バケット内の指定されたディレクトリとオブジェクトにアクセスするためのさまざまな権限をサードパーティユーザーに付与する方法を示しています。
log ディレクトリにある次のオブジェクトには、過去 3 日間のユーザーの OSS アクセスログが格納されています: log/date1.txt、log/date2.txt、log/date3.txt。 テクニカルサポートチームは、アクセスが遅い、オブジェクトのアップロードに失敗するなどの報告された問題のトラブルシューティングを行うために、これら 3 つのオブジェクトに格納されているログを表示する必要があります。 この場合、バケットポリシーを構成して、他のユーザーに log ディレクトリ内のオブジェクトにアクセスするための権限を付与できます。 詳細については、「バケットポリシーを構成して他のユーザーに OSS リソースへのアクセスを承認する」をご参照ください。
examplebucket 内の destfolder/2021/photo.jpg オブジェクトは、2021 年の春の遠足で撮影された従業員グループの写真です。 すべての従業員がこのオブジェクトにアクセスできるようにしたいと考えています。 この場合、オブジェクトのアクセス制御リスト (ACL) を public-read に設定できます。 詳細については、「オブジェクト ACL」をご参照ください。
ディレクトリの作成
次の方法を使用してディレクトリを作成できます。
ディレクトリを個別に作成するだけでなく、オブジェクトをアップロードするときにオブジェクト名のプレフィックスを指定することで、ディレクトリを自動的に作成することもできます。 たとえば、データをアップロードするパスとして exampledir/demo.txt を指定し、バケットに exampledir ディレクトリが存在しない場合、OSS は自動的に exampledir ディレクトリを作成します。
OSS コンソールの使用
OSS コンソールにログインします。
左側のナビゲーションウィンドウで、バケットリスト をクリックします。 [バケット] ページで、目的のバケットを見つけてクリックします。
左側のナビゲーションツリーで、オブジェクト管理 > オブジェクト を選択します。
オブジェクト ページで、ディレクトリの作成 をクリックします。
ディレクトリの作成 パネルで、ディレクトリ名 パラメータを構成します。
ディレクトリ名は、次の要件を満たしている必要があります。
ディレクトリ名は UTF-8 文字である必要があり、絵文字を含めることはできません。
スラッシュ (
/
) は、サブディレクトリを示すためにディレクトリ名で使用されます。 複数スラッシュ (/) を含むディレクトリ名を指定して、ディレクトリ内にサブディレクトリを作成できます。 ディレクトリ名は、スラッシュ (/
) またはバックスラッシュ (\
) で始めることはできません。 ディレクトリ名に連続したスラッシュ (/
) を含めることはできません。サブディレクトリの名前を連続した 2 つのピリオド (
..
) にすることはできません。ディレクトリ名は、1 ~ 254 文字の長さである必要があります。
OK をクリックします。
ossbrowser の使用
ossbrowser を使用すると、OSS コンソールで実行できるのと同じオブジェクトレベルの操作を実行できます。 ossbrowser の画面上の指示に従って、ディレクトリを作成できます。 詳細については、「ossbrowser の使用」をご参照ください。
OSS SDK の使用
次のサンプルコードは、一般的なプログラミング言語の OSS SDK を使用してディレクトリを作成する方法の例を示しています。 他のプログラミング言語の OSS SDK を使用してディレクトリを作成する方法の詳細については、「概要」をご参照ください。
import com.aliyun.oss.ClientException;
import com.aliyun.oss.OSS;
import com.aliyun.oss.common.auth.*;
import com.aliyun.oss.OSSClientBuilder;
import com.aliyun.oss.OSSException;
import java.io.ByteArrayInputStream;
public class Demo {
public static void main(String[] args) throws Exception {
// In this example, the endpoint of the China (Hangzhou) region is used. Specify your actual endpoint.
String endpoint = "https://oss-cn-hangzhou.aliyuncs.com";
// For security purposes, we recommend that you do not save access credentials in the project code. In this example, access credentials are obtained from environment variables. Before you run the sample code, make sure that the environment variables are configured.
EnvironmentVariableCredentialsProvider credentialsProvider = CredentialsProviderFactory.newEnvironmentVariableCredentialsProvider();
// Specify the name of the bucket. Example: examplebucket.
String bucketName = "examplebucket";
// Specify the name of the directory that you want to create by using Method 1.
String dirName = "exampledir/";
// Specify the name of the directory that you want to create by using Method 2.
String dirName2 = "exampledir1/";
// Create an OSSClient instance.
OSS ossClient = new OSSClientBuilder().build(endpoint, credentialsProvider);
try {
// Method 1: Call the createDirectory operation to create a directory. Before you use this method to create a directory, you must enable the hierarchical namespace feature.
ossClient.createDirectory(bucketName, dirName);
// Method 2: Upload an empty string to create a directory.
ossClient.putObject(bucketName, dirName2, new ByteArrayInputStream("".getBytes()));
} catch (OSSException oe) {
System.out.println("Caught an OSSException, which means your request made it to OSS, "
+ "but was rejected with an error response for some reason.");
System.out.println("Error Message:" + oe.getErrorMessage());
System.out.println("Error Code:" + oe.getErrorCode());
System.out.println("Request ID:" + oe.getRequestId());
System.out.println("Host ID:" + oe.getHostId());
} catch (ClientException ce) {
System.out.println("Caught an ClientException, which means the client encountered "
+ "a serious internal problem while trying to communicate with OSS, "
+ "such as not being able to access the network.");
System.out.println("Error Message:" + ce.getMessage());
} finally {
if (ossClient != null) {
ossClient.shutdown();
}
}
}
}
<?php
if (is_file(__DIR__ . '/../autoload.php')) {
require_once __DIR__ . '/../autoload.php';
}
if (is_file(__DIR__ . '/../vendor/autoload.php')) {
require_once __DIR__ . '/../vendor/autoload.php';
}
use OSS\Credentials\EnvironmentVariableCredentialsProvider;
use OSS\OssClient;
use OSS\CoreOssException;
// Obtain access credentials from environment variables. Before you run the sample code, make sure that the OSS_ACCESS_KEY_ID and OSS_ACCESS_KEY_SECRET environment variables are configured.
$provider = new EnvironmentVariableCredentialsProvider();
// Specify the endpoint of the region in which the bucket is located. For example, if the bucket is located in the China (Hangzhou) region, set the endpoint to https://oss-cn-hangzhou.aliyuncs.com.
$endpoint = "yourEndpoint";
// Specify the name of the bucket. Example: examplebucket.
$bucket= "examplebucket";
// Specify the name of the directory. The directory name must end with a forward slash (/).
$object = "exampledir/";
$content = "";
try{
$config = array(
"provider" => $provider,
"endpoint" => $endpoint,
);
$ossClient = new OssClient($config);
$ossClient->putObject($bucket, $object, $content);
} catch(OssException $e) {
printf(__FUNCTION__ . ": FAILED\n");
printf($e->getMessage() . "\n");
return;
}
print(__FUNCTION__ . "OK" . "\n");
// You can configure headers in upload requests to specify information about the uploaded string. For example, you can set the object ACL to private and configure the user metadata of the object.
$options = array(
OssClient::OSS_HEADERS => array(
'x-oss-object-acl' => 'private',
'x-oss-meta-info' => 'your info'
),
);
try{
$config = array(
"provider" => $provider,
"endpoint" => $endpoint,
);
$ossClient = new OssClient($config);
$ossClient->putObject($bucket, $object, $content, $options);
} catch(OssException $e) {
printf(__FUNCTION__ . ": FAILED\n");
printf($e->getMessage() . "\n");
return;
}
print(__FUNCTION__ . "OK" . "\n");
const OSS = require('ali-oss');
const client = new OSS({
// Specify the region in which the bucket is located. For example, if the bucket is located in the China (Hangzhou) region, set the region to oss-cn-hangzhou.
region: 'yourregion',
// Obtain access credentials from environment variables. Before you run the sample code, make sure that the OSS_ACCESS_KEY_ID and OSS_ACCESS_KEY_SECRET environment variables are configured.
accessKeyId: process.env.OSS_ACCESS_KEY_ID,
accessKeySecret: process.env.OSS_ACCESS_KEY_SECRET
// Specify the name of the bucket.
bucket: 'examplebucket',
});
async function putBuffer () {
try {
// Specify the name of the directory. The directory name must end with a forward slash (/).
const result = await client.put('exampledir/', new Buffer(''));
console.log(result);
} catch (e) {
console.log(e);
}
}
putBuffer();
# -*- coding: utf-8 -*-
import oss2
from oss2.credentials import EnvironmentVariableCredentialsProvider
# Obtain access credentials from environment variables. Before you run the sample code, make sure that the OSS_ACCESS_KEY_ID and OSS_ACCESS_KEY_SECRET environment variables are configured.
auth = oss2.ProviderAuth(EnvironmentVariableCredentialsProvider())
// Specify the endpoint of the region in which the bucket is located. For example, if the bucket is located in the China (Hangzhou) region, set the endpoint to https://oss-cn-hangzhou.aliyuncs.com.
# Specify the name of the bucket.
bucket = oss2.Bucket(auth, 'https://oss-cn-hangzhou.aliyuncs.com', 'examplebucket')
# Specify the name of the directory. The directory name must end with a forward slash (/).
bucket.put_object('exampledir/', '')
using System.Text;
using Aliyun.OSS;
// Specify the endpoint of the region in which the bucket is located. For example, if the bucket is located in the China (Hangzhou) region, set the endpoint to https://oss-cn-hangzhou.aliyuncs.com.
var endpoint = "yourEndpoint";
// Obtain access credentials from environment variables. Before you run the sample code, make sure that the OSS_ACCESS_KEY_ID and OSS_ACCESS_KEY_SECRET environment variables are configured.
var accessKeyId = Environment.GetEnvironmentVariable("OSS_ACCESS_KEY_ID");
var accessKeySecret = Environment.GetEnvironmentVariable("OSS_ACCESS_KEY_SECRET");
// Specify the name of the bucket. Example: examplebucket.
var bucketName = "examplebucket";
// Specify the name of the directory. The directory name must end with a forward slash (/).
var objectName = "exampledir/";
var objectContent = "";
// Create an OSSClient instance.
var client = new OssClient(endpoint, accessKeyId, accessKeySecret);
try
{
byte[] binaryData = Encoding.ASCII.GetBytes(objectContent);
MemoryStream requestContent = new MemoryStream(binaryData);
// Create the directory.
client.PutObject(bucketName, objectName, requestContent);
Console.WriteLine("Put object succeeded");
}
catch (Exception ex)
{
Console.WriteLine("Put object failed, {0}", ex.Message);
}
#include "oss_api.h"
#include "aos_http_io.h"
/* Specify the endpoint of the region in which the bucket is located. For example, if the bucket is located in the China (Hangzhou) region, set the endpoint to https://oss-cn-hangzhou.aliyuncs.com. */
const char *endpoint = "yourEndpoint";
/* Specify the name of the bucket. Example: examplebucket. */
const char *bucket_name = "examplebucket";
/* Specify the name of the directory. The directory name must end with a forward slash (/). */
const char *object_name = "exampledir/";
const char *object_content = "";
void init_options(oss_request_options_t *options)
{
options->config = oss_config_create(options->pool);
/* Use a char* string to initialize aos_string_t. */
aos_str_set(&options->config->endpoint, endpoint);
/* Obtain access credentials from environment variables. Before you run the sample code, make sure that the OSS_ACCESS_KEY_ID and OSS_ACCESS_KEY_SECRET environment variables are configured. */
aos_str_set(&options->config->access_key_id, getenv("OSS_ACCESS_KEY_ID"));
aos_str_set(&options->config->access_key_secret, getenv("OSS_ACCESS_KEY_SECRET"));
/* Specify whether to use CNAME. The value 0 indicates that CNAME is not used. */
options->config->is_cname = 0;
/* Configure network parameters, such as the timeout period. */
options->ctl = aos_http_controller_create(options->pool, 0);
}
int main(int argc, char *argv[])
{
/* Call the aos_http_io_initialize method in main() to initialize global resources, such as network resources and memory resources. */
if (aos_http_io_initialize(NULL, 0) != AOSE_OK) {
exit(1);
}
/* Create a memory pool to manage memory. aos_pool_t is equivalent to apr_pool_t. The code that is used to create a memory pool is included in the APR library. */
aos_pool_t *pool;
/* Create a memory pool. The value of the second parameter is NULL. This value specifies that the pool does not inherit other memory pools. */
aos_pool_create(&pool, NULL);
/* Create and initialize options. This parameter includes global configuration information, such as endpoint, access_key_id, access_key_secret, is_cname, and curl. */
oss_request_options_t *oss_client_options;
/* Allocate memory resources in the memory pool to the options. */
oss_client_options = oss_request_options_create(pool);
/* Initialize oss_client_options. */
init_options(oss_client_options);
/* Initialize the parameters. */
aos_string_t bucket;
aos_string_t object;
aos_list_t buffer;
aos_buf_t *content = NULL;
aos_table_t *headers = NULL;
aos_table_t *resp_headers = NULL;
aos_status_t *resp_status = NULL;
aos_str_set(&bucket, bucket_name);
aos_str_set(&object, object_name);
aos_list_init(&buffer);
content = aos_buf_pack(oss_client_options->pool, object_content, strlen(object_content));
aos_list_add_tail(&content->node, &buffer);
/* Upload the object. */
resp_status = oss_put_object_from_buffer(oss_client_options, &bucket, &object, &buffer, headers, &resp_headers);
/* Determine whether the object is uploaded. */
if (aos_status_is_ok(resp_status)) {
printf("put object from buffer succeeded\n");
} else {
printf("put object from buffer failed\n");
}
/* Release the memory pool. This operation releases memory resources allocated for the request. */
aos_pool_destroy(pool);
/* Release the allocated global resources. */
aos_http_io_deinitialize();
return 0;
}
ossutil の使用
ossutil を使用してディレクトリを作成できます。 詳細については、「mkdir」をご参照ください。
OSS API の使用
ビジネスで高度なカスタマイズが必要な場合は、RESTful API を直接呼び出すことができます。 API を直接呼び出すには、コードに署名計算を含める必要があります。 詳細については、「PutObject and CreateDirectory」をご参照ください。
ディレクトリの名前変更
バケットに対して階層型名前空間機能が有効になっている場合は、バケット内のディレクトリの名前を直接変更できます。
OSS コンソールの使用
OSS コンソールにログインします。
左側のナビゲーションウィンドウで、バケットリスト をクリックします。 [バケット] ページで、目的のバケットを見つけてクリックします。
左側のナビゲーションツリーで、オブジェクト管理 > オブジェクト を選択します。
ディレクトリの名前を変更または移動します。
操作
手順
ディレクトリの名前変更
名前を変更するディレクトリの名前にポインタを移動し、
アイコンをクリックします。 ディレクトリ名は、スラッシュ (/) で始めることはできません。
ディレクトリの移動
ディレクトリを移動する手順は、ディレクトリの名前を変更する手順と似ています。 違いは、ディレクトリを移動するときに、ディレクトリの新しい名前にスラッシュ (/) を追加する必要があることです。 ディレクトリを移動する方法の例を次に示します。
subdir サブディレクトリを destdir ディレクトリから destfolder ディレクトリに移動するには、新しいディレクトリ名を /destfolder/subdir に設定します。
subdir サブディレクトリを destdir ディレクトリから現在のバケットのルートディレクトリに移動するには、新しいディレクトリ名を /subdir に設定します。
OSS SDK の使用
さまざまなプログラミング言語の OSS SDK の中で、Java 3.12.0 以降の OSS SDK のみがディレクトリの名前変更をサポートしています。 次のサンプルコードは、Java 用 OSS SDK を使用してディレクトリの名前を変更する方法の例を示しています。
import com.aliyun.oss.ClientException;
import com.aliyun.oss.OSS;
import com.aliyun.oss.common.auth.*;
import com.aliyun.oss.OSSClientBuilder;
import com.aliyun.oss.OSSException;
import com.aliyun.oss.model.*;
public class Demo {
public static void main(String[] args) throws Exception {
// Specify the endpoint of the region in which the bucket is located. For example, if the bucket is located in the China (Hangzhou) region, set the endpoint to https://oss-cn-hangzhou.aliyuncs.com.
String endPoint = "yourEndpoint";
// For security purposes, we recommend that you do not save access credentials in the project code. In this example, access credentials are obtained from environment variables. Before you run the sample code, make sure that the environment variables are configured.
EnvironmentVariableCredentialsProvider credentialsProvider = CredentialsProviderFactory.newEnvironmentVariableCredentialsProvider();
// Specify the name of the bucket. Example: examplebucket.
String bucketName = "examplebucket";
// Specify the absolute path of the source directory. Do not include the bucket name in the absolute path.
String sourceDir = "exampledir";
// Specify the absolute path of the destination directory that is in the same bucket as the source directory. Do not include the bucket name in the absolute path.
String destinationDir = "newexampledir";
// Create an OSSClient instance.
OSS ossClient = new OSSClientBuilder().build(endPoint, credentialsProvider);
try {
// Change the absolute path of the source directory to the path of the destination directory.
RenameObjectRequest renameObjectRequest = new RenameObjectRequest(bucketName, sourceDir, destinationDir);
ossClient.renameObject(renameObjectRequest);
} catch (OSSException oe) {
System.out.println("Caught an OSSException, which means your request made it to OSS, "
+ "but was rejected with an error response for some reason.");
System.out.println("Error Message:" + oe.getErrorMessage());
System.out.println("Error Code:" + oe.getErrorCode());
System.out.println("Request ID:" + oe.getRequestId());
System.out.println("Host ID:" + oe.getHostId());
} catch (ClientException ce) {
System.out.println("Caught an ClientException, which means the client encountered "
+ "a serious internal problem while trying to communicate with OSS, "
+ "such as not being able to access the network.");
System.out.println("Error Message:" + ce.getMessage());
} finally {
if (ossClient != null) {
ossClient.shutdown();
}
}
}
}
OSS API の使用
ビジネスで高度なカスタマイズが必要な場合は、RESTful API を直接呼び出すことができます。 API を直接呼び出すには、コードに署名計算を含める必要があります。 詳細については、「名前の変更」をご参照ください。
バケットに対して階層型名前空間機能が有効になっていない場合に、バケット内のディレクトリの名前を変更するには、バケット内のすべてのオブジェクトをリストし、オブジェクトを新しいディレクトリにコピーし、古いディレクトリ内のオブジェクトを削除する必要があります。
多数のオブジェクトをコピーする必要がある場合は、データオンライン移行を使用してオブジェクトを移行できます。 詳細については、「Alibaba Cloud OSS バケット間でデータを移行する」をご参照ください。
ossbrowser の使用
ossbrowser を使用すると、OSS コンソールで実行できるのと同じオブジェクトレベルの操作を実行できます。 ossbrowser の画面上の指示に従って、ディレクトリの名前を変更できます。 ossbrowser の使用方法の詳細については、「ossbrowser の使用」をご参照ください。
OSS SDK の使用
OSS SDK を使用してディレクトリの名前を変更する場合、いくつかの操作が必要になります。 OSS SDK を使用してディレクトリの名前を変更するコード例については、「オブジェクトのリスト」、「オブジェクトのコピー」、「オブジェクトの削除」をご参照ください。
ossutil の使用
ossutil を使用してディレクトリの名前を変更できます。 ディレクトリの名前変更に関連する ossutil コマンドの詳細については、「ls」、「オブジェクトのコピー」、「rm」をご参照ください。
OSS API の使用
ビジネスで高度なカスタマイズが必要な場合は、RESTful API を直接呼び出すことができます。 API を直接呼び出すには、コードに署名計算を含める必要があります。 詳細については、「ListObjectsV2 (GetBucketV2)」または「GetBucket (ListObjects)」、「CopyObject」、「DeleteObject」をご参照ください。
ディレクトリの削除
不要になったディレクトリを削除できます。
ディレクトリを削除すると、サブディレクトリとディレクトリ内のすべてのオブジェクトが同期的に削除されます。 ディレクトリを削除する際は注意が必要です。
OSS コンソールの使用
OSS コンソールにログインします。
左側のナビゲーションウィンドウで、バケットリスト をクリックします。 [バケット] ページで、目的のバケットを見つけてクリックします。
左側のナビゲーションツリーで、オブジェクト管理 > オブジェクト を選択します。
オブジェクト ページで、目的のディレクトリを削除します。
重要ディレクトリを削除するときは、[タスクリスト] パネルを更新または閉じないでください。 そうしないと、削除が中断されます。
バケットに対して階層型名前空間機能が有効になっている場合
削除するディレクトリを見つけて、[操作] 列の [削除] をクリックします。 表示されるメッセージで、[OK] をクリックします。
ディレクトリとディレクトリ内のオブジェクトは完全に削除されます。
バケットに対して階層型名前空間機能が無効になっている場合
バケットに対して階層型名前空間とバージョニング機能が無効になっている場合、階層型名前空間機能が有効になっているバケットからディレクトリを削除するのと同じ方法で、バケットからディレクトリを削除します。
階層型名前空間機能が無効になっていて、バケットに対してバージョニング機能が有効になっている場合は、次のいずれかの方法を使用してディレクトリを削除できます。
削除されたディレクトリを以前のバージョンとして保存する
オブジェクトリストの右上隅で、前のバージョンの表示 を 非表示 に設定します。
削除するディレクトリを見つけて、[操作] 列の 削除 をクリックします。 表示されるメッセージで、OK をクリックします。
削除されたディレクトリとディレクトリ内のオブジェクトは、復元可能な以前のバージョンとして保存されます。 オブジェクトの以前のバージョンを復元する方法の詳細については、「以前のバージョンの復元」をご参照ください。
ディレクトリを完全に削除する
オブジェクトリストの右上隅で、前のバージョンの表示 を 表示 に設定します。
削除するディレクトリを見つけて、[操作] 列の 完全に削除 をクリックします。 表示されるメッセージで、OK をクリックします。
ディレクトリとディレクトリ内のオブジェクトは完全に削除されます。
バケットに対してバージョニングが無効になっている場合
削除するディレクトリを見つけて、[操作] 列の 完全に削除 をクリックします。 表示されるメッセージで、OK をクリックします。
ディレクトリとディレクトリ内のオブジェクトは完全に削除されます。
バケットに対してバージョニングが有効または一時停止されている場合
削除されたディレクトリを以前のバージョンとして保存する
オブジェクトリストの右上隅で、前のバージョンの表示 を 非表示 に設定します。
削除するディレクトリを見つけて、[操作] 列の 削除 をクリックします。 表示されるメッセージで、OK をクリックします。
削除されたディレクトリとディレクトリ内のオブジェクトは、復元可能な以前のバージョンとして保存されます。 オブジェクトの以前のバージョンを復元する方法の詳細については、「以前のバージョンの復元」をご参照ください。
ディレクトリを完全に削除する
オブジェクトリストの右上隅で、前のバージョンの表示 を 表示 に設定します。
削除するディレクトリを見つけて、[操作] 列の 完全に削除 をクリックします。 表示されるメッセージで、OK をクリックします。
ディレクトリとディレクトリ内のオブジェクトは完全に削除されます。
タスクリスト パネルで、削除の進行状況を確認します。
OSS が削除タスクを実行しているときに、次の操作を実行できます。
削除完了 をクリックして、完了したタスクをタスクリストから削除します。
すべて一時停止 をクリックして、実行中のすべての削除タスクを一時停止します。 タスクが一時停止されている場合は、次の操作を実行できます。
[操作] 列で、開始 をクリックしてタスクを再開します。
[操作] 列で、削除 をクリックしてタスクを削除します。 タスクを削除すると、タスクによって削除されなかったオブジェクトは保持されます。
すべて開始 をクリックして、一時停止されているすべてのタスクを再開します。
ossbrowser の使用
ossbrowser を使用すると、OSS コンソールで実行できるのと同じオブジェクトレベルの操作を実行できます。 ossbrowser の画面上の指示に従って、ディレクトリを削除できます。 詳細については、「ossbrowser の使用」をご参照ください。
OSS SDK の使用
次のサンプルコードは、一般的なプログラミング言語の OSS SDK を使用してディレクトリを削除する方法の例を示しています。 他のプログラミング言語の OSS SDK を使用してディレクトリを削除する方法の詳細については、「概要」をご参照ください。
オブジェクトを削除するときに、削除するすべてのオブジェクトの名前に含まれるプレフィックスを指定できます。 この場合、指定されたプレフィックスを含む名前のディレクトリと、ディレクトリ内のすべてのオブジェクトが削除されます。 たとえば、examplebucket から log ディレクトリとディレクトリ内のすべてのオブジェクトを削除するには、プレフィックスを log/ に設定します。
import com.aliyun.oss.ClientException;
import com.aliyun.oss.OSS;
import com.aliyun.oss.common.auth.*;
import com.aliyun.oss.OSSClientBuilder;
import com.aliyun.oss.OSSException;
import com.aliyun.oss.model.*;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.util.ArrayList;
import java.util.List;
public class Demo {
public static void main(String[] args) throws Exception {
// In this example, the endpoint of the China (Hangzhou) region is used. Specify your actual endpoint.
String endpoint = "https://oss-cn-hangzhou.aliyuncs.com";
// For security purposes, we recommend that you do not save access credentials in the project code. In this example, access credentials are obtained from environment variables. Before you run the sample code, make sure that the environment variables are configured.
EnvironmentVariableCredentialsProvider credentialsProvider = CredentialsProviderFactory.newEnvironmentVariableCredentialsProvider();
// Specify the name of the bucket. Example: examplebucket.
String bucketName = "examplebucket";
// Specify the absolute path of the directory. Do not include the bucket name in the absolute path.
String directoryName = "exampledir";
// Specify the full path of the directory that you want to delete. Do not include the bucket name in the full path.
final String prefix = "log/";
// Create an OSSClient instance.
OSS ossClient = new OSSClientBuilder().build(endpoint, credentialsProvider);
try {
// Method 1: Call deleteDirectory to recursively delete a directory. Before you use this method to delete a directory, you must enable the hierarchical namespace feature.
DeleteDirectoryRequest deleteDirectoryRequest = new DeleteDirectoryRequest(bucketName, directoryName);
deleteDirectoryRequest.setDeleteRecursive(true);
DeleteDirectoryResult deleteDirectoryResult = ossClient.deleteDirectory(deleteDirectoryRequest);
// Display the deletion result.
// You can delete up to 100 directories and objects at a time. If only a portion of directories and objects are deleted, the server returns nextDeleteToken. You can use nextDeleteToken to continue deleting the remaining data.
// nextDeleteToken helps the server find the object or directory after which the next delete operation begins.
String nextDeleteToken = deleteDirectoryResult.getNextDeleteToken();
System.out.println("delete next token:" + nextDeleteToken);
// Display the absolute path of the deleted directory.
System.out.println("delete dir name :" + deleteDirectoryResult.getDirectoryName());
// Display the total number of deleted objects and directories.
System.out.println("delete number:" + deleteDirectoryResult.getDeleteNumber());
// Method 2: Call listObjects to traverse and delete the directory and all objects in the directory.
String nextMarker = null;
ObjectListing objectListing = null;
do {
ListObjectsRequest listObjectsRequest = new ListObjectsRequest(bucketName)
.withPrefix(prefix)
.withMarker(nextMarker);
objectListing = ossClient.listObjects(listObjectsRequest);
if (objectListing.getObjectSummaries().size() > 0) {
List<String> keys = new ArrayList<String>();
for (OSSObjectSummary s : objectListing.getObjectSummaries()) {
System.out.println("key name: " + s.getKey());
keys.add(s.getKey());
}
DeleteObjectsRequest deleteObjectsRequest = new DeleteObjectsRequest(bucketName).withKeys(keys).withEncodingType("url");
DeleteObjectsResult deleteObjectsResult = ossClient.deleteObjects(deleteObjectsRequest);
List;String> deletedObjects = deleteObjectsResult.getDeletedObjects();
try {
for(String obj : deletedObjects) {
String deleteObj = URLDecoder.decode(obj, "UTF-8");
System.out.println(deleteObj);
}
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
}
nextMarker = objectListing.getNextMarker();
} while (objectListing.isTruncated());
} catch (OSSException oe) {
System.out.println("Caught an OSSException, which means your request made it to OSS, "
+ "but was rejected with an error response for some reason.");
System.out.println("Error Message:" + oe.getErrorMessage());
System.out.println("Error Code:" + oe.getErrorCode());
System.out.println("Request ID:" + oe.getRequestId());
System.out.println("Host ID:" + oe.getHostId());
} catch (ClientException ce) {
System.out.println("Caught an ClientException, which means the client encountered "
+ "a serious internal problem while trying to communicate with OSS, "
+ "such as not being able to access the network.");
System.out.println("Error Message:" + ce.getMessage());
} finally {
if (ossClient != null) {
ossClient.shutdown();
}
}
}
}
<?php
if (is_file(__DIR__ . '/../autoload.php')) {
require_once __DIR__ . '/../autoload.php';
}
if (is_file(__DIR__ . '/../vendor/autoload.php')) {
require_once __DIR__ . '/../vendor/autoload.php';
}
use OSS\OssClient;
use OSS\Core\OssException;
// Obtain access credentials from environment variables. Before you run the sample code, make sure that the OSS_ACCESS_KEY_ID and OSS_ACCESS_KEY_SECRET environment variables are configured.
$accessKeyId = getenv("OSS_ACCESS_KEY_ID");
$accessKeySecret = getenv("OSS_ACCESS_KEY_SECRET");
// Specify the endpoint of the region in which the bucket is located. For example, if the bucket is located in the China (Hangzhou) region, set the endpoint to https://oss-cn-hangzhou.aliyuncs.com.
$endpoint = "yourEndpoint";
// Specify the name of the bucket.
$bucket = "examplebucket";
try {
$ossClient = new OssClient($accessKeyId, $accessKeySecret, $endpoint, false);
$option = array(
OssClient::OSS_MARKER => null,
// Specify the full path of the directory that you want to delete. Do not include the bucket name in the full path.
OssClient::OSS_PREFIX => "log/",
OssClient::OSS_DELIMITER=>'',
);
$bool = true;
while ($bool){
$result = $ossClient->listObjects($bucket,$option);
$objects = array();
if(count($result->getObjectList()) > 0){
foreach ($result->getObjectList() as $key => $info){
printf("key name:".$info->getKey().PHP_EOL);
$objects[] = $info->getKey();
}
// Delete the directory and all objects in the directory.
$delObjects = $ossClient->deleteObjects($bucket, $objects);
foreach ($delObjects as $info){
$obj = strval($info);
printf("Delete ".$obj." : Success" . PHP_EOL);
}
}
if($result->getIsTruncated() === 'true'){
$option[OssClient::OSS_MARKER] = $result->getNextMarker();
}else{
$bool = false;
}
}
printf("Delete Objects : OK" . PHP_EOL);
} catch (OssException $e) {
printf("Delete Objects : Failed" . PHP_EOL);
printf($e->getMessage() . PHP_EOL);
return;
}
const OSS = require('ali-oss');
const client = new OSS({
// Specify the region in which the bucket is located. For example, if the bucket is located in the China (Hangzhou) region, set the region to oss-cn-hangzhou.
region: 'yourregion',
// Obtain access credentials from environment variables. Before you run the sample code, make sure that the OSS_ACCESS_KEY_ID and OSS_ACCESS_KEY_SECRET environment variables are configured.
accessKeyId: process.env.OSS_ACCESS_KEY_ID,
accessKeySecret: process.env.OSS_ACCESS_KEY_SECRET,
// Specify the name of the bucket.
bucket: 'yourbucketname'
});
// Handle request failures, prevent the interruption of promise.all, and return failure causes and the names of objects that failed to be deleted.
async function handleDel(name, options) {
try {
await client.delete(name);
} catch (error) {
error.failObjectName = name;
return error;
}
}
// Delete multiple objects at a time.
async function deletePrefix(prefix) {
const list = await client.list({
prefix: prefix,
});
list.objects = list.objects || [];
const result = await Promise.all(list.objects.map((v) => handleDel(v.name)));
console.log(result);
}
// Delete the directory and all objects in the directory.
deletePrefix('log/')
# -*- coding: utf-8 -*-
import oss2
from oss2.credentials import EnvironmentVariableCredentialsProvider
# Obtain access credentials from environment variables. Before you run the sample code, make sure that the OSS_ACCESS_KEY_ID and OSS_ACCESS_KEY_SECRET environment variables are configured.
auth = oss2.ProviderAuth(EnvironmentVariableCredentialsProvider())
// Specify the endpoint of the region in which the bucket is located. For example, if the bucket is located in the China (Hangzhou) region, set the endpoint to https://oss-cn-hangzhou.aliyuncs.com.
# Specify the name of the bucket.
bucket = oss2.Bucket(auth, 'https://oss-cn-hangzhou.aliyuncs.com', 'examplebucket')
prefix = "exampledir/"
// Delete the directory and all objects in the directory.
for obj in oss2.ObjectIterator(bucket, prefix=prefix):
bucket.delete_object(obj.key)
package main
import (
"fmt"
"os"
"github.com/aliyun/aliyun-oss-go-sdk/oss"
)
func main() {
// Obtain access credentials from environment variables. Before you run the sample code, make sure that the OSS_ACCESS_KEY_ID and OSS_ACCESS_KEY_SECRET environment variables are configured.
provider, err := oss.NewEnvironmentVariableCredentialsProvider()
if err != nil {
fmt.Println("Error:", err)
os.Exit(-1)
}
// Create an OSSClient instance.
// Specify the endpoint of the region in which the bucket is located. For example, if the bucket is located in the China (Hangzhou) region, set the endpoint to https://oss-cn-hangzhou.aliyuncs.com. Specify your actual endpoint.
client, err := oss.New("yourEndpoint", "", "", oss.SetCredentialsProvider(&provider))
if err != nil {
fmt.Println("Error:", err)
os.Exit(-1)
}
// Specify the name of the bucket.
bucket, err := client.Bucket("examplebucket")
if err != nil {
fmt.Println("Error:", err)
os.Exit(-1)
}
marker := oss.Marker("")
// Specify the full path of the directory that you want to delete. Do not include the bucket name in the full path.
prefix := oss.Prefix("log/")
count := 0
for {
lor, err := bucket.ListObjects(marker, prefix)
if err != nil {
fmt.Println("Error:", err)
os.Exit(-1)
}
objects := []string{}
for _, object := range lor.Objects {
objects = append(objects, object.Key)
}
// Delete the directory and all objects in the directory.
// Set the oss.DeleteObjectsQuiet parameter to true. This setting indicates that OSS does not return a message after objects are deleted.
delRes, err := bucket.DeleteObjects(objects, oss.DeleteObjectsQuiet(true))
if err != nil {
fmt.Println("Error:", err)
os.Exit(-1)
}
if len(delRes.DeletedObjects) > 0 {
fmt.Println("these objects deleted failure,", delRes.DeletedObjects)
os.Exit(-1)
}
count += len(objects)
prefix = oss.Prefix(lor.Prefix)
marker = oss.Marker(lor.NextMarker)
if !lor.IsTruncated {
break
}
}
fmt.Printf("success,total delete object count:%d\n", count)
}
#include <alibabacloud/oss/OssClient.h>
using namespace AlibabaCloud::OSS;
int main(void)
{
/* Initialize information about the account that is used to access OSS. */
/* Specify the endpoint of the region in which the bucket is located. For example, if the bucket is located in the China (Hangzhou) region, set the endpoint to https://oss-cn-hangzhou.aliyuncs.com. */
std::string Endpoint = "yourEndpoint";
/* Specify the name of the bucket. */
std::string BucketName = "examplebucket";
/* Specify the full path of the directory that you want to delete. Do not include the bucket name in the full path. */
std::string keyPrefix = "log/";
/* Initialize resources, such as network resources. */
InitializeSdk();
ClientConfiguration conf;
/* Obtain access credentials from environment variables. Before you run the sample code, make sure that the OSS_ACCESS_KEY_ID and OSS_ACCESS_KEY_SECRET environment variables are configured. */
auto credentialsProvider = std::make_shared<EnvironmentVariableCredentialsProvider>();
OssClient client(Endpoint, credentialsProvider, conf);
std::string nextMarker = "";
bool isTruncated = false;
do {
ListObjectsRequest request(BucketName);
request.setPrefix(keyPrefix);
request.setMarker(nextMarker);
auto outcome = client.ListObjects(request);
if (!outcome.isSuccess()) {
/* Handle exceptions. */
std::cout << "ListObjects fail" <<
",code:" << outcome.error().Code() <<
",message:" << outcome.error().Message() <<
",requestId:" << outcome.error().RequestId() << std::endl;
break;
}
for (const auto& object : outcome.result().ObjectSummarys()) {
DeleteObjectRequest request(BucketName, object.Key());
/* Delete the directory and all objects in the directory. */
auto delResult = client.DeleteObject(request);
}
nextMarker = outcome.result().NextMarker();
isTruncated = outcome.result().IsTruncated();
} while (isTruncated);
/* Release resources, such as network resources. */
ShutdownSdk();
return 0;
}
ossutil の使用
ossutil では、rm コマンドの prefix オプションでディレクトリの名前を指定することで、ディレクトリを削除できます。 詳細については、「rm」をご参照ください。
OSS API の使用
ビジネスで高度なカスタマイズが必要な場合は、RESTful API を直接呼び出すことができます。 API を直接呼び出すには、コードに署名計算を含める必要があります。 詳細については、「DeleteObject and DeleteDirectory」をご参照ください。
ディレクトリサイズのクエリ
いくつかの方法を使用して、ディレクトリ内のオブジェクトの合計サイズをクエリできます。
OSS コンソールの使用
OSS コンソール にログインします。
左側のナビゲーションウィンドウで、バケットリスト をクリックします。 [バケット] ページで、目的のバケットを見つけてクリックします。
オブジェクト ページで、サイズをクエリするディレクトリを見つけ、[オブジェクトサイズ] 列の更新アイコンをクリックします。
次の例に示すように、OSS はディレクトリ内のオブジェクトの合計サイズを表示します。
OSS SDK の使用
次のサンプルコードは、一般的なプログラミング言語の OSS SDK を使用してディレクトリのサイズをクエリする方法の例を示しています。 他のプログラミング言語の OSS SDK を使用してディレクトリのサイズをクエリする方法の詳細については、「概要」をご参照ください。
Java
import com.aliyun.oss.ClientException;
import com.aliyun.oss.OSS;
import com.aliyun.oss.common.auth.*;import com.aliyun.oss.OSS;
import com.aliyun.oss.common.auth.*;
import com.aliyun.oss.common.auth.*;
import com.aliyun.oss.OSSClientBuilder;
import com.aliyun.oss.OSSException;
import com.aliyun.oss.model.*;
import java.util.List;
public class Demo {
public static void main(String[] args) throws Exception {
// In this example, the endpoint of the China (Hangzhou) region is used. Specify your actual endpoint.
String endpoint = "https://oss-cn-hangzhou.aliyuncs.com";
// Obtain access credentials from environment variables. Before you run the sample code, make sure that the OSS_ACCESS_KEY_ID and OSS_ACCESS_KEY_SECRET environment variables are configured.
EnvironmentVariableCredentialsProvider credentialsProvider = CredentialsProviderFactory.newEnvironmentVariableCredentialsProvider();
// Specify the name of the bucket. Example: examplebucket.
String bucketName = "examplebucket";
// Specify the prefix in the names of the objects that you want to list. Example: exampledir/object. If you want to traverse the sizes of objects and directories in the root directory, leave this parameter empty.
String keyPrefix = "exampledir/object";
// Specify the region in which the bucket is located. For example, if the bucket is located in the China (Hangzhou) region, set the region to cn-hangzhou.
String region = "cn-hangzhou";
// Create an OSSClient instance.
ClientBuilderConfiguration clientBuilderConfiguration = new ClientBuilderConfiguration();
clientBuilderConfiguration.setSignatureVersion(SignVersion.V4);
OSS ossClient = OSSClientBuilder.create()
.endpoint(endpoint)
.credentialsProvider(credentialsProvider)
.clientConfiguration(clientBuilderConfiguration)
.region(region)
.build(););
try {
ObjectListing objectListing = null;
do {
// By default, 100 objects or directories are listed at a time.
ListObjectsRequest request = new ListObjectsRequest(bucketName).withDelimiter("/").withPrefix(keyPrefix);
if (objectListing != null) {
request.setMarker(objectListing.getNextMarker());
}
objectListing = ossClient.listObjects(request);
List<String> folders = objectListing.getCommonPrefixes();
for (String folder : folders) {
System.out.println(folder + " : " + (calculateFolderLength(ossClient, bucketName, folder) / 1024) + "KB");
}
List<OSSObjectSummary> sums = objectListing.getObjectSummaries();
for (OSSObjectSummary s : sums) {
System.out.println(s.getKey() + " : " + (s.getSize() / 1024) + "KB");
}
} while (objectListing.isTruncated());
} catch (OSSException oe) {
System.out.println("Caught an OSSException, which means your request made it to OSS, "
+ "but was rejected with an error response for some reason.");
System.out.println("Error Message:" + oe.getErrorMessage());
System.out.println("Error Code:" + oe.getErrorCode());
System.out.println("Request ID:" + oe.getRequestId());
System.out.println("Host ID:" + oe.getHostId());
} catch (ClientException ce) {
System.out.println("Caught an ClientException, which means the client encountered "
+ "a serious internal problem while trying to communicate with OSS, "
+ "such as not being able to access the network.");
System.out.println("Error Message:" + ce.getMessage());
} finally {
if (ossClient != null) {
ossClient.shutdown();
}
}
}
// List the sizes of objects in a specific directory in a bucket.
private static long calculateFolderLength(OSS ossClient, String bucketName, String folder) {
long size = 0L;
ObjectListing objectListing = null;
do {
// The default value of MaxKeys is 100. The maximum value of MaxKeys is 1000.
ListObjectsRequest request = new ListObjectsRequest(bucketName).withPrefix(folder).withMaxKeys(1000);
if (objectListing != null) {
request.setMarker(objectListing.getNextMarker());
}
objectListing = ossClient.listObjects(request);
List<OSSObjectSummary> sums = objectListing.getObjectSummaries();
for (OSSObjectSummary s : sums) {
size += s.getSize();
}
} while (objectListing.isTruncated());
return size;
}
}
PHP
<?php
if (is_file(__DIR__ . '/../autoload.php')) {
require_once __DIR__ . '/../autoload.php';
}
if (is_file(__DIR__ . '/../vendor/autoload.php')) {
require_once __DIR__ . '/../vendor/autoload.php';
}
require_once __DIR__ . '/Common.php';
use OSS\Credentials\EnvironmentVariableCredentialsProvider;
use OSS\OssClient;
use OSS\CoreOssException;
// Obtain access credentials from environment variables. Before you run the sample code, make sure that the OSS_ACCESS_KEY_ID and OSS_ACCESS_KEY_SECRET environment variables are configured.
$provider = new EnvironmentVariableCredentialsProvider();
// In this example, the endpoint of the China (Hangzhou) region is used. Specify your actual endpoint.
$endpoint = "https://oss-cn-hangzhou.aliyuncs.com";
// Specify the name of the bucket. Example: examplebucket.
$bucket= "examplebucket";
$config = array(
"provider" => $provider,
"endpoint" => $endpoint,
"signatureVersion" => OssClient::OSS_SIGNATURE_VERSION_V4,
"region"=> "cn-hangzhou"
);
$ossClient = new OssClient($config);
// Set the directory name to fun/.
$prefix = 'fun/';
$delimiter = '';
$nextMarker = '';
$maxkeys = 1000;
$options = array(
'delimiter' => $delimiter,
'prefix' => $prefix,
'max-keys' => $maxkeys,
'marker' => $nextMarker,
);
$bool = true;
$size = 0;
while ($bool){
$result = $ossClient->listObjects($bucket,$options);
foreach ($result->getObjectList() as $objInfo){
printf("object name".$objInfo->getKey().":" . ($objInfo->getSize() / 1024) . "KB".PHP_EOL);
$size+=$objInfo->getSize();
}
if($result->getIsTruncated() === 'true'){
$options['marker'] = $result->getNextMarker();
}else{
$bool = false;
}
}
printf($prefix.":" . ($size / 1024) . "KB".PHP_EOL);
Python
# -*- coding: utf-8 -*-
import oss2
from oss2.credentials import EnvironmentVariableCredentialsProvider
def CalculateFolderLength(bucket, folder):
length = 0
for obj in oss2.ObjectIterator(bucket, prefix=folder):
length += obj.size
return length
# Obtain access credentials from environment variables. Before you run the sample code, make sure that the OSS_ACCESS_KEY_ID and OSS_ACCESS_KEY_SECRET environment variables are configured.
auth = oss2.ProviderAuthV4(EnvironmentVariableCredentialsProvider())
// Specify the endpoint of the region in which the bucket is located. For example, if the bucket is located in the China (Hangzhou) region, set the endpoint to https://oss-cn-hangzhou.aliyuncs.com.
endpoint = "https://oss-cn-hangzhou.aliyuncs.com"
// Specify the ID of the region that maps to the endpoint. Example: cn-hangzhou. This parameter is required if you use the signature algorithm V4.
region = "cn-hangzhou"
// Specify the name of your bucket.
bucket = oss2.Bucket(auth, endpoint, "yourBucketName", region=region)
for obj in oss2.ObjectIterator(bucket, delimiter='/'):
if obj.is_prefix(): // Specify the operation to perform if obj is determined as a directory.
length = CalculateFolderLength(bucket, obj.key)
print('directory: ' + obj.key + ' length:' + str(length) + "Byte.")
else: // Specify the operation to perform if obj is determined as an object.
print('file:' + obj.key + ' length:' + str(obj.size) + "Byte.")
Go
package main
import (
"log"
"github.com/aliyun/aliyun-oss-go-sdk/oss"
)
func main() {
// Obtain access credentials from environment variables. Before you run the sample code, make sure that the OSS_ACCESS_KEY_ID and OSS_ACCESS_KEY_SECRET environment variables are configured.
provider, err := oss.NewEnvironmentVariableCredentialsProvider()
if err != nil {
log.Fatalf("Failed to create credentials provider: %v", err)
}
// Create an OSSClient instance.
// Specify the endpoint of the region in which the bucket is located. For example, if the bucket is located in the China (Hangzhou) region, set the endpoint to https://oss-cn-hangzhou.aliyuncs.com. Specify your actual endpoint.
// Specify the region in which the bucket is located. For example, if your bucket is located in the China (Hangzhou) region, set the region to cn-hangzhou.
client, err := oss.New("yourEndpoint", "", "", oss.SetCredentialsProvider(&provider), oss.Region("yourRegion"), oss.AuthVersion(oss.AuthV4))
if err != nil {
log.Fatalf("Failed to create OSS client: %v", err)
}
// Specify the name of the bucket.
bucketName := "yourBucketName" // Replace yourBucketName with the actual bucket name.
bucket, err := client.Bucket(bucketName)
if err != nil {
log.Fatalf("Failed to get bucket: %v", err)
}
// List the sizes of the objects in a specific directory.
prefix := "test/" // Replace test/ with the actual directory name.
marker := ""
for {
lsRes, err := bucket.ListObjects(oss.Prefix(prefix), oss.Marker(marker))
if err != nil {
log.Fatalf("Failed to list objects: %v", err)
}
// Display the listed objects and their sizes.
for _, object := range lsRes.Objects {
log.Printf("Object Key: %s, Size: %d Byte(s)\n", object.Key, object.Size)
}
// If the returned results are truncated, update the value of the marker parameter to obtain the remaining results.
if lsRes.IsTruncated {
marker = lsRes.NextMarker
} else {
break
}
}
log.Println("All objects have been listed with their sizes.")
}
ossutil の使用
ossutil を使用して、ディレクトリ内のオブジェクトの合計サイズをクエリできます。 詳細については、「ディレクトリ内のオブジェクトの現在のバージョンの合計サイズをクエリする」をご参照ください。
OSS API の使用
ビジネスで高度なカスタマイズが必要な場合は、RESTful API を直接呼び出すことができます。 API を直接呼び出すには、コードに署名計算を含める必要があります。 詳細については、「GetBucket (ListObjects)」をご参照ください。