> Portal Navigation:
>
> - Append `.md` to any URL under `https://dev.wix.com/docs/` to get its markdown version.
> - Pages are either content pages (article or reference text) or menu pages (a list of links to child pages).
> - To get a menu page, truncate any URL to a parent path and append `.md` (e.g. `https://dev.wix.com/docs/sdk.md`, `https://dev.wix.com/docs/sdk/core-modules.md`).
> - Top-level index of all portals: https://dev.wix.com/docs/llms.txt
> - Full concatenated docs: https://dev.wix.com/docs/llms-full.txt
# BulkDeleteFiles
# Package: mediaManager
# Namespace: FilesService
# Method link: https://dev.wix.com/docs/api-reference/assets/media/media-manager/files/bulk-delete-files.md
## Permission Scopes:
Manage Media Manager: SCOPE.DC-MEDIA.MANAGE-MEDIAMANAGER
## Introduction
Deletes the specified files from the Media Manager.
The deleted files are moved to the Media Manager's trash bin (`TRASH-ROOT` folder) unless permanently deleted. To permanently delete files, specify the `permanent` parameter with the value `true`. Permanently deleting files isn't reversible, so make sure that these files aren't being used in a site or in any other way as the files will no longer be accessible.
Note the following:
* The specified files can be from different folders.
* Moving multiple files at once is an asynchronous action, and may take time for the changes to appear in the Media Manager.
* Attempting to delete files that are already in the trash bin doesn't result in an error.
* If a site contains deleted media files, the deleted media files still appear on the site as the files are still in the Media Manager (in the trash bin).
* You can use Bulk Restore Files From Trash Bin to restore files from the Media Manager's trash bin.
---
## REST API
### Schema
```
Method: bulkDeleteFiles
Description: Deletes the specified files from the Media Manager.
The deleted files are moved to the Media Manager's trash bin (`TRASH-ROOT` folder) unless permanently deleted. To permanently delete files, specify the `permanent` parameter with the value `true`. Permanently deleting files isn't reversible, so make sure that these files aren't being used in a site or in any other way as the files will no longer be accessible. Note the following: * The specified files can be from different folders. * Moving multiple files at once is an asynchronous action, and may take time for the changes to appear in the Media Manager. * Attempting to delete files that are already in the trash bin doesn't result in an error. * If a site contains deleted media files, the deleted media files still appear on the site as the files are still in the Media Manager (in the trash bin). * You can use Bulk Restore Files From Trash Bin to restore files from the Media Manager's trash bin.
URL: https://www.wixapis.com/site-media/v1/bulk/files/delete
Method: POST
# Note: If the parameter `a.b` is listed under required parameters, `b` is only required if `a` is also present.
Required parameters: fileIds
Method parameters:
param name: fileIds | type: array | description: IDs of the files to move to the Media Manager's trash bin. You can also specify the files' Wix media URLs. For example, `["wix:image://v1/0abec0_b291a9349a0b4da59067f76287e386fb~mv2.jpg/leon.jpg#originWidth=3024&originHeight=4032"]`. Learn more [about the file GUID parameter](https://dev.wix.com/docs/api-reference/assets/media/media-manager/files/file-id.md). | required: true
param name: permanent | type: permanent | description: Whether the specified files are permanently deleted.
Default: `false`
Return type: BulkDeleteFilesResponse
EMPTY-OBJECT {}
```
### Examples
### Bulk delete files
```curl
curl -X POST \
'https://www.wixapis.com/site-media/v1/bulk/files/delete' \
-H 'Authorization: ' \
-H 'Content-Type: application/json' \
--data-binary '{
"fileIds": ["4acbb8_7596aeebcf5c41eca01c0d99667ac967.mp3", "3vcbb7_7446aeebcf5c41eca01c0d99665bc866.mp3"]
}'
```
---
## JavaScript SDK
### Schema
```
Method: wixClientAdmin.mediaManager.FilesService.bulkDeleteFiles(fileIds, options)
Description: Deletes the specified files from the Media Manager.
The deleted files are moved to the Media Manager's trash bin (`TRASH-ROOT` folder) unless permanently deleted. To permanently delete files, specify the `permanent` parameter with the value `true`. Permanently deleting files isn't reversible, so make sure that these files aren't being used in a site or in any other way as the files will no longer be accessible. Note the following: * The specified files can be from different folders. * Moving multiple files at once is an asynchronous action, and may take time for the changes to appear in the Media Manager. * Attempting to delete files that are already in the trash bin doesn't result in an error. * If a site contains deleted media files, the deleted media files still appear on the site as the files are still in the Media Manager (in the trash bin). * You can use Bulk Restore Files From Trash Bin to restore files from the Media Manager's trash bin.
# Note: If the parameter `a.b` is listed under required parameters, `b` is only required if `a` is also present.
Required parameters: fileIds
Method parameters:
param name: fileIds | type: array | description: IDs of the files to move to the Media Manager's trash bin. You can also pass the files' Wix media URLs. For example, `["wix:image://v1/0abec0_b291a9349a0b4da59067f76287e386fb~mv2.jpg/leon.jpg#originWidth=3024&originHeight=4032"]`. Learn more in the File and Folder GUIDs article. | required: true
param name: options | type: BulkDeleteFilesOptions none
- name: permanent | type: boolean | description: Whether the specified files are permanently deleted.
Default: `false`
Return type: PROMISE
EMPTY-OBJECT {}
```
### Examples
### Bulk delete files (with elevated permissions)
```javascript
import { files } from '@wix/media';
import { auth } from '@wix/essentials';
const elevatedBulkDeleteFiles = auth.elevate(files.bulkDeleteFiles);
/* Sample fileIds value:
* [
* 'w8ide0_v12i2pi4549locqdfeb5yy5b8iyh39az.pdf',
* 'w8ide0_ye3x8yyf5izwe01ovn682pa76bzrrcyt.pdf'
* ]
*
* Sample options value:
* {
* permanent: true
* }
*/
async function myBulkDeleteFilesFunction(fileIds, options) {
try {
await elevatedBulkDeleteFiles(fileIds, options);
console.log('Permanently deleted files.');
return;
} catch (error) {
console.error(error);
// Handle the error
}
}
/* Promise resolves to void */
```
### Bulk delete files
```javascript
import { files } from '@wix/media';
/* Sample fileIds value:
* [
* 'w8ide0_v12i2pi4549locqdfeb5yy5b8iyh39az.pdf',
* 'w8ide0_ye3x8yyf5izwe01ovn682pa76bzrrcyt.pdf'
* ]
*
* Sample options value:
* {
* permanent: true
* }
*/
async function myBulkDeleteFilesFunction(fileIds, options) {
try {
await files.bulkDeleteFiles(fileIds, options);
console.log('Permanently deleted files.');
return;
} catch (error) {
console.error(error);
// Handle the error
}
}
/* Promise resolves to void */
```
### Bulk delete all files found in a chosen folder (with $w)
This code shows a page where the visitor chooses a folder by typing the folder's name in an input box, and then all the files in the chosen folder are deleted. Only visitors with permission to manage the site's media would have access to this page.
```javascript
/**********************************************
* Backend code - bulk-delete-files.web.js/ts *
*********************************************/
import { Permissions, webMethod } from '@wix/web-methods';
import { files } from '@wix/media';
import { auth } from '@wix/essentials';
export const deleteFiles = webMethod(Permissions.Anyone, async (fileIds, options) => {
try {
const elevatedBulkDeleteFiles = auth.elevate(files.bulkDeleteFiles);
await elevatedBulkDeleteFiles(fileIds, options);
console.log(`Permanently deleted files with ids: ${fileIds.toString()}.`);
return true;
} catch (error) {
console.error(error);
}
});
export const searchFileIds = webMethod(Permissions.Anyone, async (parentFolderId) => {
try {
const options = { parentFolder: parentFolderId };
const elevatedSearchFiles = auth.elevate(files.searchFiles);
const returnedFiles = await elevatedSearchFiles(options);
const fileIds = returnedFiles.files.map((file) => {
return file._id;
});
return fileIds;
} catch (error) {
console.error(error);
}
});
/*************
* Page code *
************/
import { deleteFiles, searchFileIds } from 'backend/bulk-delete-files.web';
$w.onReady(() => {
$w('#delete').onClick(async () => {
const isDeletePermanently = $w('#deletePermanently').checked;
const options = { permanent: isDeletePermanently };
const parentFolder = $w('#parentFolder').value;
const fileIds = await searchFileIds(parentFolder);
await deleteFiles(fileIds, options);
$w('#successMessage').show();
});
});
```
### bulkDeleteFiles (self-hosted)
Self-hosted SDK calls require you to [create a client](https://dev.wix.com/docs/sdk/articles/work-with-the-sdk/about-the-wix-client.md).
```javascript
import { createClient } from '@wix/sdk';
import { files } from '@wix/media';
// Import the auth strategy for the relevant access type
// Import the relevant host module if needed
const myWixClient = createClient ({
modules: { files },
// Include the auth strategy and host as relevant
});
async function bulkDeleteFiles(fileIds,options) {
const response = await myWixClient.files.bulkDeleteFiles(fileIds,options);
};
```
---