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

ファイルを削除する

remove API を使用してストレージバケットからファイルを削除できます。ファイルが ID で保護されている場合、そのファイルを削除できるのはそのファイルを所有するユーザーのみです。

let removedObject = try await Amplify.Storage.remove(
path: .fromString("public/example/path")
)
print("Deleted \(removedObject)")
let sink = Amplify.Publisher.create {
try await Amplify.Storage.remove(
path: .fromString("public/example/path")
)
}.sink {
if case let .failure(error) = $0 {
print("Failed: \(error)")
}
}
receiveValue: { removedObject in
print("Deleted \(removedObject)")
}

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

bucket オプションを指定して、特定のバケットから削除操作を実行できます。

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

let removedObject = try await Amplify.Storage.remove(
path: .fromString("public/example/path"),
options: .init(
bucket: .fromOutputs(name: "secondBucket")
)
)

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

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