Name:
interface
Value:
Amplify has re-imagined the way frontend developers build fullstack applications. Develop and deploy without the hassle.
Gen1 DocsLegacy

Page updated Mar 26, 2026

ファイルプロパティをリストする

すべてのファイルをダウンロードすることなく、ファイルをリストできます。これは、Amplify Library for Storageのlist APIを使用して実行できます。

ファイルをリストする

次の例は、public/photos/パス内のすべてのオブジェクトをリストします:

let listResult = try await Amplify.Storage.list(
path: .fromString("public/photos/")
)
listResult.items.forEach { item in
print("Path: \(item.path)")
}
let sink = Amplify.Publisher.create {
try await Amplify.Storage.list(
path: .fromString("public/photos/")
)
}.sink {
if case let .failure(error) = $0 {
print("Failed: \(error)")
}
}
receiveValue: { listResult in
listResult.items.forEach { item in
print("Path: \(item.path)")
}
}

指定されたパス内の末尾のスラッシュ/に注意してください。

public/photosをパスとして使用した場合、public/photos01.jpgのようなファイルにもマッチします。

指定されたバケットからファイルをリストする

bucketオプションを指定することで、特定のバケットからリスト操作を実行できます。

.fromOutputs(name:)を使用して、Amplify Backendで割り当てられたターゲットバケット名を表す文字列を指定できます。

let listResult = try await Amplify.Storage.list(
path: .fromString("public/photos/"),
options: .init(
bucket: .fromOutputs(name: "secondBucket")
)
)

.fromBucketInfo(_:)を使用してバケット名とリージョンを直接指定することもできます。

let listResult = try await Amplify.Storage.list(
path: .fromString("public/photos/"),
options: .init(
bucket: .fromBucketInfo(.init(
bucketName: "another-bucket-name",
region: "another-bucket-region")
)
)
)

ネストされたサブパスから結果を除外する

デフォルトでは、list APIは、ネストされたサブパス内のオブジェクトを含む、指定されたパス内に含まれるすべてのオブジェクトを返します。

例えば、前のpublic/photos/パスには、これらのオブジェクトが含まれます:

Path: public/photos/photo1.jpg
Path: public/photos/vacation/photo1.jpg
Path: public/photos/thumbnails/photo1.jpg

vacationおよびthumbnailsサブパス内のオブジェクトを除外するには、subpathStrategyオプションを.excludeに設定します:

let listResult = try await Amplify.Storage.list(
path: .fromString("public/photos/"),
options: .init(
subpathStrategy: .exclude
)
)
listResult.items.forEach { item in
print("Path: \(item.path)")
}
listResult.excludedSubpaths.forEach { subpath in
print("Subpath: \(subpath)")
}
let sink = Amplify.Publisher.create {
try await Amplify.Storage.list(
path: .fromString("public/photos/"),
options: .init(
subpathStrategy: .exclude
)
)
}.sink {
if case let .failure(error) = $0 {
print("Failed: \(error)")
}
}
receiveValue: { listResult in
listResult.items.forEach { item in
print("Path: \(item.path)")
}
listResult.excludedSubpaths.forEach { subpath in
print("Subpath: \(subpath)")
}
}

レスポンスにはpublic/photos/パス内のオブジェクトのみが含まれ、除外されたサブパスのリストも提供します:

Path: public/photos/photo01.jpg
Subpath: public/photos/vacation/
Subpath: public/photos/thumbnails/

デフォルトの区切り文字は"/"ですが、カスタム区切り文字を指定して変更できます:

let listResult = try await Amplify.Storage.list(
path: .fromString("public/photos-"),
options: .init(
subpathStrategy: .exclude(delimitedBy: "-")
)
)
let sink = Amplify.Publisher.create {
try await Amplify.Storage.list(
path: .fromString("public/photos-"),
options: .init(
subpathStrategy: .exclude(delimitedBy: "-")
)
)
}.sink {
if case let .failure(error) = $0 {
print("Failed: \(error)")
}
}
receiveValue: { listResult in
// ...
}

すべてのlistオプション

オプション説明
subpathStrategySubpathStrategyサブパスからコンテンツをリストするときに使用する戦略
pageSizeUIntサーバーからファイルリストを取得するときに取得するエントリ数の制限を示す1~1,000の間の数
bucketStorageBucketオブジェクトが保存されているバケット
nextTokenStringリストを再開するページオフセットを示す文字列。

pageSizeが利用可能な全ファイルサイズより低く設定されている場合、単一のlist呼び出しはすべてのファイルのサブセットのみを返します。複数の呼び出しですべてのファイルをリストするには、ユーザーは前のレスポンスからnextToken値を使用できます。