---
title: "Remove files"
section: "frontend/storage"
platforms: ["android", "angular", "flutter", "javascript", "nextjs", "react", "react-native", "swift", "vue"]
gen: 2
last-updated: "2026-03-25T17:40:00.000Z"
url: "https://docs.amplify.aws/react/frontend/storage/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.

<!-- Platform: react, angular, javascript, vue, nextjs, react-native -->
## Remove a single file

You can also perform a remove operation from a specific bucket by providing the target bucket's assigned name from Amplify Backend in `bucket` option.

```javascript
import { remove } from 'aws-amplify/storage';

try {
  await remove({ 
    path: 'album/2024/1.jpg',
    // Alternatively, path: ({identityId}) => `album/${identityId}/1.jpg`
    bucket: 'assignedNameInAmplifyBackend', // Specify a target bucket using name assigned in Amplify Backend
  });
} catch (error) {
  console.log('Error ', error);
}
```

Alternatively, you can also pass in an object by specifying the bucket name and region from the console.

```javascript
import { remove } from 'aws-amplify/storage';

try {
  await remove({ 
    path: 'album/2024/1.jpg',
    // Alternatively, provide bucket name from console and associated region
    bucket: {
      bucketName: 'bucket-name-from-console',
      region: 'us-east-2'
    }

  });
} catch (error) {
  console.log('Error ', error);
}
```
<!-- /Platform -->

<!-- Platform: react, angular, javascript, vue, nextjs -->
## Remove folders

You can remove entire folders and their contents by providing a folder path. The remove API will automatically detect folders and perform batch deletion of all contained files.

```javascript
import { remove } from 'aws-amplify/storage';

try {
  await remove({
    path: 'album/2024/'
  });
} catch (error) {
  console.error(error);
}
```

### Folder deletion with progress tracking

For large folders, you can track the deletion progress and handle any failures:

```javascript
import { remove } from 'aws-amplify/storage';

try {
  const result = await remove({ 
    path: 'large-folder/',
    options: {
      onProgress: (fileBatch) => {
        console.log(fileBatch);
      }
    }
  });
  
  console.log('Success', result);
} catch (error) {
  console.log('Error during folder deletion:', error);
}
```

### Cancellable folder deletion

You can cancel folder deletion operations, useful for user-initiated cancellations or when navigating away from a page.

When you call `remove()` without `await`, it returns a cancellable operation object with a `result` property and `cancel()` method. This differs from `await remove()` which directly returns the result but cannot be cancelled.

```javascript
import { remove } from 'aws-amplify/storage';

let deleteOperation;

// Start deletion when user clicks delete button
function handleDeleteFolder() {
  // remove() returns { result: Promise, cancel: Function }
  deleteOperation = remove({ 
    path: 'user-uploads/large-dataset/',
    options: {
      onProgress: (fileBatch) => {
        updateProgressBar(fileBatch.deleted?.length || 0);
      }
    }
  });

  // Access the promise via .result property
  deleteOperation.result.then(result => {
    console.log('Success', result);
  }).catch(error => {
    if (error.name === 'CanceledError') {
      console.log('Deletion cancelled by user');
    } else {
      console.log('Error:', error);
    }
  });
}

// Cancel when user clicks cancel or navigates away
function handleCancel() {
  if (deleteOperation) {
    deleteOperation.cancel();
  }
}
```
<!-- /Platform -->

<!-- Platform: android -->

#### [Java]

```java
Amplify.Storage.remove(
    StoragePath.fromString("public/myUploadedFileName.txt"),
    result -> Log.i("MyAmplifyApp", "Successfully removed: " + result.getPath()),
    error -> Log.e("MyAmplifyApp", "Remove failure", error)
);
```

#### [Kotlin - Callbacks]

```kotlin
Amplify.Storage.remove(StoragePath.fromString("public/myUploadedFileName.txt"),
    { Log.i("MyAmplifyApp", "Successfully removed: ${it.path}") },
    { Log.e("MyAmplifyApp", "Remove failure", it) }
)
```

#### [Kotlin - Coroutines]

```kotlin
try {
    val result = Amplify.Storage.remove(StoragePath.fromString("public/myUploadedFileName.txt"))
    Log.i("MyAmplifyApp", "Successfully removed: ${result.path}")
} catch (error: StorageException) {
    Log.e("MyAmplifyApp", "Remove failure", error)
}
```

#### [RxJava]

```java
RxAmplify.Storage.remove(StoragePath.fromString("public/myUploadedFileName.txt"))
        .subscribe(
            result -> Log.i("MyAmplifyApp", "Successfully removed: " + result.getPath()),
            error -> Log.e("MyAmplifyApp", "Remove failure", error)
        );
```

## Remove files from a specified bucket

You can also perform a remove operation to a specific bucket by providing the `bucket` option. You can pass in a string representing the target bucket's assigned name in Amplify Backend.

#### [Java]

```java
StorageBucket secondBucket = StorageBucket.fromOutputs("secondBucket");
StorageRemoveOptions options = StorageRemoveOptions.builder()
    .bucket(secondBucket)
    .build();

Amplify.Storage.remove(
    StoragePath.fromString("public/myUploadedFileName.txt"), 
    options,
    result -> Log.i("MyAmplifyApp", "Successfully removed: " + result.getPath()),
    error -> Log.e("MyAmplifyApp", "Remove failure", error)
);
```

#### [Kotlin - Callbacks]

```kotlin
val secondBucket = StorageBucket.fromOutputs("secondBucket")
val options = StorageRemoveOptions.builder()
    .bucket(secondBucket)
    .build()

Amplify.Storage.remove(StoragePath.fromString("public/myUploadedFileName.txt"), options,
    { Log.i("MyAmplifyApp", "Successfully removed: ${it.path}") },
    { Log.e("MyAmplifyApp", "Remove failure", it) }
)
```

#### [Kotlin - Coroutines]

```kotlin
val secondBucket = StorageBucket.fromOutputs("secondBucket")
val options = StorageRemoveOptions.builder()
    .bucket(secondBucket)
    .build()

try {
    val result = Amplify.Storage.remove(StoragePath.fromString("public/myUploadedFileName.txt"), options)
    Log.i("MyAmplifyApp", "Successfully removed: ${result.path}")
} catch (error: StorageException) {
    Log.e("MyAmplifyApp", "Remove failure", error)
}
```

#### [RxJava]

```java     
StorageBucket secondBucket = StorageBucket.fromOutputs("secondBucket");
StorageRemoveOptions options = StorageRemoveOptions.builder()
    .bucket(secondBucket)
    .build(); 
RxAmplify.Storage.remove(StoragePath.fromString("public/myUploadedFileName.txt"), options)
        .subscribe(
            result -> Log.i("MyAmplifyApp", "Successfully removed: " + result.getPath()),
            error -> Log.e("MyAmplifyApp", "Remove failure", error)
        );
```

Alternatively, you can also pass in an object by specifying the bucket name and region from the console.

#### [Java]

```java
BucketInfo bucketInfo = new BucketInfo("second-bucket-name-from-console", "us-east-2");
StorageBucket secondBucket = StorageBucket.fromBucketInfo(bucketInfo);
StorageRemoveOptions options = StorageRemoveOptions.builder()
    .bucket(secondBucket)
    .build(); 

Amplify.Storage.remove(
    StoragePath.fromString("public/myUploadedFileName.txt"),
    options,
    result -> Log.i("MyAmplifyApp", "Successfully removed: " + result.getPath()),
    error -> Log.e("MyAmplifyApp", "Remove failure", error)
);
```

#### [Kotlin - Callbacks]

```kotlin
val bucketInfo = BucketInfo("second-bucket-name-from-console", "us-east-2")
val secondBucket = StorageBucket.fromBucketInfo(bucketInfo)
val options = StorageRemoveOptions.builder()
    .bucket(secondBucket)
    .build()

Amplify.Storage.remove(StoragePath.fromString("public/myUploadedFileName.txt"), options,
    { Log.i("MyAmplifyApp", "Successfully removed: ${it.path}") },
    { Log.e("MyAmplifyApp", "Remove failure", it) }
)
```

#### [Kotlin - Coroutines]

```kotlin
val bucketInfo = BucketInfo("second-bucket-name-from-console", "us-east-2")
val secondBucket = StorageBucket.fromBucketInfo(bucketInfo)
val options = StorageRemoveOptions.builder()
    .bucket(secondBucket)
    .build()

try {
    val result = Amplify.Storage.remove(StoragePath.fromString("public/myUploadedFileName.txt"), options)
    Log.i("MyAmplifyApp", "Successfully removed: ${result.path}")
} catch (error: StorageException) {
    Log.e("MyAmplifyApp", "Remove failure", error)
}
```

#### [RxJava]

```java
BucketInfo bucketInfo = new BucketInfo("second-bucket-name-from-console", "us-east-2");
StorageBucket secondBucket = StorageBucket.fromBucketInfo(bucketInfo);
StorageRemoveOptions options = StorageRemoveOptions.builder()
    .bucket(secondBucket)
    .build(); 

RxAmplify.Storage.remove(StoragePath.fromString("public/myUploadedFileName.txt"), options)
        .subscribe(
            result -> Log.i("MyAmplifyApp", "Successfully removed: " + result.getPath()),
            error -> Log.e("MyAmplifyApp", "Remove failure", error)
        );
```

<!-- /Platform -->

<!-- Platform: swift -->

#### [Async/Await]

```swift
let removedObject = try await Amplify.Storage.remove(
    path: .fromString("public/example/path")
)
print("Deleted \(removedObject)")
```

#### [Combine]

```swift
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.

#### [From Outputs]
You can use `.fromOutputs(name:)` to provide a string representing the target bucket's assigned name in the Amplify Backend.

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

#### [From Bucket Info]
You can also use `.fromBucketInfo(_:)` to provide a bucket name and region directly.

```swift
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")
        )    
    )
)
```

<!-- /Platform -->

<!-- Platform: flutter -->
You can also perform a `remove` operation to a specific bucket by providing the `bucket` option. You can pass in a `StorageBucket` object representing the target bucket from the name defined in the Amplify Backend.

```dart
final result = await Amplify.Storage.remove(
  path: const StoragePath.fromString('path/to/file.txt'),
  options: StorageRemoveOptions(
    // highlight-start
    // Specify a target bucket using name assigned in Amplify Backend
    bucket: StorageBucket.fromOutputs('secondBucket'),
    // highlight-end
  ),
).result;
```

Alternatively, you can also pass in an object by specifying the bucket name and region from the console.

```dart
final result = await Amplify.Storage.remove(
  path: const StoragePath.fromString('path/to/file.txt'),
  options: StorageRemoveOption(
    // highlight-start
    // Alternatively, provide bucket name from console and associated region
   bucket: StorageBucket.fromBucketInfo(
        BucketInfo(
          bucketName: 'second-bucket-name-from-console',
          region: 'us-east-2',
        ),
      ),
      // highlight-end
  ),
).result;
```

## Remove multiple Files

You can remove multiple files using `Amplify.Storage.removeMany`, as well as specify a bucket to target, the files to be removed in a batch should have the same access level:

```dart
Future<void> remove() async {
  try {
    final result = await Amplify.Storage.removeMany(
      paths: [
        const StoragePath.fromString('public/file-1.txt'),
        const StoragePath.fromString('public/file-2.txt'),
      ],
      // if this option is not provided, the default bucket in the Amplify Backend will be used
      options: StorageRemoveManyOptions(
        bucket: StorageBucket.fromOutputs('secondBucket'),
        /* Alternatively, provide bucket name from console and associated region
        bucket: StorageBucket.fromBucketInfo(
          BucketInfo(
            bucketName: 'second-bucket-name-from-console',
            region: 'us-east-2',
          ),
        ),
        */
      ),
    ).result;
    safePrint('Removed files: ${result.removedItems}');
  } on StorageException catch (e) {
    safePrint(e.message);
  }
}
```
<!-- /Platform -->

<!-- Platform: react, angular, javascript, vue, nextjs, react-native -->
## More `remove` options

Option | Type | Default | Description |
| -- | :--: | :--: | ----------- |
| bucket | string \| <br />\{ bucketName: string;<br/> region: string; \} | Default bucket and region from Amplify configuration | A string representing the target bucket's assigned name in Amplify Backend or an object specifying the bucket name and region from the console.<br/><br/>Read more at [Configure additional storage buckets](/[platform]/build-a-backend/storage/set-up-storage/#configure-additional-storage-buckets) |
| expectedBucketOwner | string | Optional | The account ID that owns requested bucket. |
| onProgress | (fileBatch: \{<br/>deleted?: \{path: string\}[];<br/>failed?: \{path: string; code: string; message: string\}[];<br/>\}) => void | Optional | Callback function for tracking folder deletion progress. Called after each batch of files is processed during folder deletion operations. |
<!-- /Platform -->
