Need to configure your backend?See Build a Backend →
ファイルを削除する
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") ) ))