Page updated Nov 12, 2023

Remove files

Delete stored data from the storage bucket. To remove a file, you need to provide the key. accessLevel can be 'guest', 'private', or 'protected', defaulting to 'guest'. Files can only be deleted for the current user. Deletion capabilities do not extend to files associated with other users.

Guest level remove

import { remove } from 'aws-amplify/storage'; try { await remove({ key: filename }); } catch (error) { console.log('Error ', error); }
1import { remove } from 'aws-amplify/storage';
2
3try {
4 await remove({ key: filename });
5} catch (error) {
6 console.log('Error ', error);
7}

Protected level remove

import { remove } from 'aws-amplify/storage'; try { await remove({ key: filename, options: { accessLevel: 'protected' } }); } catch (error) { console.log('Error ', error); }
1import { remove } from 'aws-amplify/storage';
2
3try {
4 await remove({ key: filename, options: { accessLevel: 'protected' } });
5} catch (error) {
6 console.log('Error ', error);
7}

Private level remove

import { remove } from 'aws-amplify/storage'; try { await remove({ key: filename, options: { accessLevel: 'private' } }); } catch (error) { console.log('Error ', error); }
1import { remove } from 'aws-amplify/storage';
2
3try {
4 await remove({ key: filename, options: { accessLevel: 'private' } });
5} catch (error) {
6 console.log('Error ', error);
7}