Remove files
Files can be removed from a storage bucket using the remove
API. If a file is protected by an identity Id, only the user who owns the file will be able to remove it.
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)")}
Remove files from a specified bucket
You can perform a remove operation from a specific bucket by providing the bucket
option.
You can use .fromOutputs(name:)
to provide a string representing the target bucket's assigned name in the Amplify Backend.
let removedObject = try await Amplify.Storage.remove( path: .fromString("public/example/path"), options: .init( bucket: .fromOutputs(name: "secondBucket") ))
You can also use .fromBucketInfo(_:)
to provide a bucket name and region directly.
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") ) ))