Search.../

bulkDeleteFolders( )

Developer Preview

Temporarily deletes the specified folders from the Media Manager.

Description

The bulkDeleteFolders() function returns a Promise that resolves when the folders are deleted.

The deleted folders are moved to the Media Manager's TRASH_ROOT folder (trash bin) unless permanently deleted. To permanently delete folders, pass the permanent parameter with the value true. Permanently deleting folders isn't reversible, so make sure that the files in these folders aren't being used in a site or in any other way as the files will no longer be accessible.

Notes:

  • When a folder is deleted, the files in that folder are deleted.
  • The specified folders can be from different parent folders.
  • Moving multiple folders at once is an asynchronous action, and may take time for the changes to appear in the Media Manager.
  • Attempting to delete folders that are already in the trash bin doesn't result in an error.
  • If your site contains files from a non-permanently deleted media folder, the files still appear on your site as the deleted folder is still in the Media Manager (in the trash bin).
  • You can use the bulkRestoreFoldersFromTrashBin() endpoint to restore folders from the Media Manager's trash bin.
Admin Method

This function requires elevated permissions to run. This function is not universal and runs only on the backend.

Syntax

function bulkDeleteFolders(folderIds: Array<string>, options: BulkDeleteFoldersOptions): Promise<void>

bulkDeleteFolders Parameters

NAME
TYPE
DESCRIPTION
folderIds
Array<
string
>

IDs of the folders to move to the Media Manager's trash bin.

options
Optional
BulkDeleteFoldersOptions

Options to use when deleting folders.

Returns

Return Type:

Promise<
void
>

Was this helpful?

Bulk delete folders

Copy Code
1import { folders } from 'wix-media.v2';
2import { elevate } from 'wix-auth';
3
4/* Sample folderIds value:
5 * [
6 * '302fc049d70c41dea33fa4a27ab481ba',
7 * 's8ze556gf8wfao3us62nx25ww3lr595a'
8 * ]
9 */
10
11async function myBulkDeleteFoldersFunction(folderIds) {
12 try {
13 const elevatedBulkDeleteFolders = elevate(folders.bulkDeleteFolders);
14 const deletedFolders = await elevatedBulkDeleteFolders(folderIds);
15
16 console.log('Successfully moved folders to trash.');
17 return deletedFolders;
18 } catch (error) {
19 console.error(error);
20 // Handle the error
21 }
22}
23
24/* Promise resolves to void */
Bulk permanently delete folders

Copy Code
1import { folders } from 'wix-media.v2';
2import { elevate } from 'wix-auth';
3
4/* Sample folderIds value:
5 * [
6 * '302fc049d70c41dea33fa4a27ab481ba',
7 * 's8ze556gf8wfao3us62nx25ww3lr595a',
8 * 'c956d69906414e7faf8a0ad81117b17d'
9 * ]
10 *
11 * Sample options value:
12 * {
13 * permanent: true
14 * }
15 */
16
17async function myBulkDeleteFoldersFunction(folderIds, options) {
18 try {
19 const elevatedBulkDeleteFolders = elevate(folders.bulkDeleteFolders);
20 const deletedFolders = await elevatedBulkDeleteFolders(folderIds, options);
21
22 console.log('Successfully permanently deleted files.');
23 return deletedFolders;
24 } catch (error) {
25 console.error(error);
26 // Handle the error
27 }
28}
29
30/* Promise resolves to void */
Bulk delete all folders

This code is an example of a page on which a visitor chooses a folder from a dropdown list, and then deletes all folders found within that folder.

Copy Code
1/**************************************
2 * Backend code - delete-folders.jsw *
3 *************************************/
4
5import { folders } from 'wix-media.v2';
6import { elevate } from 'wix-auth';
7
8export async function deleteFolders(folderIds) {
9 try {
10 const elevatedBulkDeleteFolders = elevate(folders.bulkDeleteFolders);
11 const deletedFolders = await elevatedBulkDeleteFolders(folderIds);
12
13 console.log('Successfully moved folders to trash.');
14 return deletedFolders;
15 } catch (error) {
16 console.error(error);
17 }
18}
19
20export async function listFolders() {
21 try {
22 const elevatedListFolders = elevate(folders.listFolders)
23 const foldersList = await elevatedListFolders();
24
25 return foldersList;
26 } catch (error) {
27 console.error(error);
28 }
29}
30
31export async function searchFolders(options) {
32 try {
33 const elevatedSearchFolders = elevate(folders.searchFolders)
34 const foldersFound = await elevatedSearchFolders(options);
35
36 return foldersFound;
37 } catch (error) {
38 console.error(error);
39 }
40}
41
42
43/*************
44 * Page code *
45 ************/
46
47import { deleteFolders, listFolders, searchFolders } from 'backend/delete-folders';
48
49$w.onReady(async () => {
50 await populateFoldersDropdown();
51
52 $w('#bulkDelete').onClick(async () => {
53 const searchOptions = { rootFolder: $w('#foldersDropdown').value};
54
55 const foldersToDelete = await searchFolders(searchOptions);
56 const foldersIdsToDelete = foldersToDelete.map((folder) => {
57 return folder._id;
58 });
59 await deleteFolders(foldersIdsToDelete);
60
61 console.log(`Successfully deleted all folders found in ${$w('#foldersDropdown').label}.`)
62 $w('#bulkDeleteSuccessMsg').show();
63 });
64});
65
66async function populateFoldersDropdown() {
67 const folders = await listFolders();
68 const dropdownOptions = folders.map((folder) => {
69 return {
70 label: folder.displayName,
71 value: folder._id
72 };
73 });
74
75 $w('#foldersDropdown').options = dropdownOptions;
76};
77