Search.../

listDeletedFiles( )

Retrieves a list of files in the Media Manager's trash bin.

Description

The listDeletedFiles() function returns a Promise that resolves to an array of the specified deleted files' descriptors and cursor information.

Note: The Media Manager's trash bin (TRASH_ROOT folder) only contains temporarily deleted files, not permanently deleted files.

To retrieve a list of non-deleted files, use the listFiles() function.

Admin Method

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

Syntax

function listDeletedFiles(options: ListDeletedFilesOptions): Promise<ListDeletedFilesResponse>

listDeletedFiles Parameters

NAME
TYPE
DESCRIPTION
options
Optional
ListDeletedFilesOptions

Options to use when listing deleted files from the trash bin.

Returns

Return Type:

Promise<
ListDeletedFilesResponse
>
NAME
TYPE
DESCRIPTION
files
Array<
FileDescriptor
>

List of files in the Media Manager's trash bin.

nextCursor
PagingMetadataV2

The next cursor if it exists.

Was this helpful?

List deleted files (dashboard page code)

Copy Code
1import { files } from 'wix-media.v2';
2
3async function myListDeletedFilesFunction() {
4 try {
5 const deletedFiles = await files.listDeletedFiles();
6
7 console.log('Files in trash:', deletedFiles)
8 return deletedFiles;
9 } catch (error) {
10 console.error(error);
11 // Handle the error
12 }
13}
14
15/* Promise resolves to:
16 * {
17 * "files": [
18 * {
19 * "_createdDate": "2023-08-09T08:45:42.000Z",
20 * "_id": "d4dde1_32288e20a5aa4213a52b15426fb27c9f~mv2.png",
21 * "_updatedDate": "2023-08-09T08:45:42.000Z",
22 * "displayName": "image1.png",
23 * "hash": "864d607a1ea270efbac32def181f039f",
24 * "internalTags": [
25 * "_fileOrigin_uploaded"
26 * ],
27 * "labels": [],
28 * "media": {
29 * "image": {
30 * "colors": {
31 * "palette": [
32 * {
33 * "rgb": {
34 * "b": 247,
35 * "g": 247,
36 * "r": 247
37 * }
38 * },
39 * {
40 * "rgb": {
41 * "b": 142,
42 * "g": 140,
43 * "r": 140
44 * }
45 * },
46 * {
47 * "rgb": {
48 * "b": 192,
49 * "g": 218,
50 * "r": 141
51 * }
52 * },
53 * {
54 * "rgb": {
55 * "b": 195,
56 * "g": 137,
57 * "r": 149
58 * }
59 * },
60 * {
61 * "rgb": {
62 * "b": 228,
63 * "g": 143,
64 * "r": 183
65 * }
66 * },
67 * {
68 * "rgb": {
69 * "b": 250,
70 * "g": 62,
71 * "r": 152
72 * }
73 * },
74 * {
75 * "rgb": {
76 * "b": 16,
77 * "g": 16,
78 * "r": 16
79 * }
80 * },
81 * {
82 * "rgb": {
83 * "b": 140,
84 * "g": 199,
85 * "r": 60
86 * }
87 * },
88 * {
89 * "rgb": {
90 * "b": 120,
91 * "g": 194,
92 * "r": 242
93 * }
94 * },
95 * {
96 * "rgb": {
97 * "b": 158,
98 * "g": 203,
99 * "r": 103
100 * }
101 * }
102 * ],
103 * "prominent": {
104 * "rgb": {
105 * "b": 247,
106 * "g": 247,
107 * "r": 247
108 * }
109 * }
110 * },
111 * "faces": [],
112 * "image": "wix:image://v1/d4dde1_32288e20a5aa4213a52b15426fb27c9f~mv2.png/image1.png#originWidth=1170&originHeight=2532"
113 * }
114 * },
115 * "mediaType": "IMAGE",
116 * "operationStatus": "READY",
117 * "parentFolderId": "trash-root",
118 * "private": false,
119 * "siteId": "3ecba886-4267-11ee-be56-0242ac120002",
120 * "sizeInBytes": "394945",
121 * "state": "OK",
122 * "thumbnailUrl": "https://static.wixstatic.com/media/d4dde1_32288e20a5aa4213a52b15426fb27c9f~mv2.png",
123 * "url": "https://static.wixstatic.com/media/d4dde1_32288e20a5aa4213a52b15426fb27c9f~mv2.png"
124 * },
125 * {
126 * "_createdDate": "2023-08-09T08:45:37.000Z",
127 * "_id": "d4dde1_8dd2bfe6121f43b29ebeaa63988abf54.svg",
128 * "_updatedDate": "2023-08-09T08:45:37.000Z",
129 * "displayName": "vectorArt1.svg",
130 * "hash": "e379083c3675d7f7891da00c0708539c",
131 * "internalTags": [
132 * "_fileOrigin_uploaded"
133 * ],
134 * "labels": [],
135 * "media": {
136 * "image": {
137 * "faces": [],
138 * "image": "wix:image://v1/d4dde1_8dd2bfe6121f43b29ebeaa63988abf54.svg/vectorArt1.svg#originWidth=1177&originHeight=2501"
139 * }
140 * },
141 * "mediaType": "VECTOR",
142 * "operationStatus": "READY",
143 * "parentFolderId": "trash-root",
144 * "private": false,
145 * "siteId": "3ecba886-4267-11ee-be56-0242ac120002",
146 * "sizeInBytes": "119475",
147 * "state": "OK",
148 * "thumbnailUrl": "https://static.wixstatic.com/shapes/d4dde1_8dd2bfe6121f43b29ebeaa63988abf54.svg",
149 * "url": "https://static.wixstatic.com/shapes/d4dde1_8dd2bfe6121f43b29ebeaa63988abf54.svg"
150 * }
151 * ],
152 * "nextCursor": {
153 * "cursors": {
154 * "next": ""
155 * },
156 * "hasNext": false
157 * }
158 * }
159 */
List deleted files (export from backend code)

Copy Code
1import { Permissions, webMethod } from 'wix-web-module';
2import { files } from 'wix-media.v2';
3import { elevate } from 'wix-auth';
4
5export const myListDeletedFilesFunction = webMethod(Permissions.Anyone, async () => {
6 try {
7 const elevatedListDeletedFiles = elevate(files.listDeletedFiles)
8 const deletedFiles = await elevatedListDeletedFiles();
9
10 console.log('Files in trash:', deletedFiles)
11 return deletedFiles;
12 } catch (error) {
13 console.error(error);
14 // Handle the error
15 }
16});
17
18/* Promise resolves to:
19 * {
20 * "files": [
21 * {
22 * "_createdDate": "2023-08-09T08:45:42.000Z",
23 * "_id": "d4dde1_32288e20a5aa4213a52b15426fb27c9f~mv2.png",
24 * "_updatedDate": "2023-08-09T08:45:42.000Z",
25 * "displayName": "image1.png",
26 * "hash": "864d607a1ea270efbac32def181f039f",
27 * "internalTags": [
28 * "_fileOrigin_uploaded"
29 * ],
30 * "labels": [],
31 * "media": {
32 * "image": {
33 * "colors": {
34 * "palette": [
35 * {
36 * "rgb": {
37 * "b": 247,
38 * "g": 247,
39 * "r": 247
40 * }
41 * },
42 * {
43 * "rgb": {
44 * "b": 142,
45 * "g": 140,
46 * "r": 140
47 * }
48 * },
49 * {
50 * "rgb": {
51 * "b": 192,
52 * "g": 218,
53 * "r": 141
54 * }
55 * },
56 * {
57 * "rgb": {
58 * "b": 195,
59 * "g": 137,
60 * "r": 149
61 * }
62 * },
63 * {
64 * "rgb": {
65 * "b": 228,
66 * "g": 143,
67 * "r": 183
68 * }
69 * },
70 * {
71 * "rgb": {
72 * "b": 250,
73 * "g": 62,
74 * "r": 152
75 * }
76 * },
77 * {
78 * "rgb": {
79 * "b": 16,
80 * "g": 16,
81 * "r": 16
82 * }
83 * },
84 * {
85 * "rgb": {
86 * "b": 140,
87 * "g": 199,
88 * "r": 60
89 * }
90 * },
91 * {
92 * "rgb": {
93 * "b": 120,
94 * "g": 194,
95 * "r": 242
96 * }
97 * },
98 * {
99 * "rgb": {
100 * "b": 158,
101 * "g": 203,
102 * "r": 103
103 * }
104 * }
105 * ],
106 * "prominent": {
107 * "rgb": {
108 * "b": 247,
109 * "g": 247,
110 * "r": 247
111 * }
112 * }
113 * },
114 * "faces": [],
115 * "image": "wix:image://v1/d4dde1_32288e20a5aa4213a52b15426fb27c9f~mv2.png/image1.png#originWidth=1170&originHeight=2532"
116 * }
117 * },
118 * "mediaType": "IMAGE",
119 * "operationStatus": "READY",
120 * "parentFolderId": "trash-root",
121 * "private": false,
122 * "siteId": "3ecba886-4267-11ee-be56-0242ac120002",
123 * "sizeInBytes": "394945",
124 * "state": "OK",
125 * "thumbnailUrl": "https://static.wixstatic.com/media/d4dde1_32288e20a5aa4213a52b15426fb27c9f~mv2.png",
126 * "url": "https://static.wixstatic.com/media/d4dde1_32288e20a5aa4213a52b15426fb27c9f~mv2.png"
127 * },
128 * {
129 * "_createdDate": "2023-08-09T08:45:37.000Z",
130 * "_id": "d4dde1_8dd2bfe6121f43b29ebeaa63988abf54.svg",
131 * "_updatedDate": "2023-08-09T08:45:37.000Z",
132 * "displayName": "vectorArt1.svg",
133 * "hash": "e379083c3675d7f7891da00c0708539c",
134 * "internalTags": [
135 * "_fileOrigin_uploaded"
136 * ],
137 * "labels": [],
138 * "media": {
139 * "image": {
140 * "faces": [],
141 * "image": "wix:image://v1/d4dde1_8dd2bfe6121f43b29ebeaa63988abf54.svg/vectorArt1.svg#originWidth=1177&originHeight=2501"
142 * }
143 * },
144 * "mediaType": "VECTOR",
145 * "operationStatus": "READY",
146 * "parentFolderId": "trash-root",
147 * "private": false,
148 * "siteId": "3ecba886-4267-11ee-be56-0242ac120002",
149 * "sizeInBytes": "119475",
150 * "state": "OK",
151 * "thumbnailUrl": "https://static.wixstatic.com/shapes/d4dde1_8dd2bfe6121f43b29ebeaa63988abf54.svg",
152 * "url": "https://static.wixstatic.com/shapes/d4dde1_8dd2bfe6121f43b29ebeaa63988abf54.svg"
153 * }
154 * ],
155 * "nextCursor": {
156 * "cursors": {
157 * "next": ""
158 * },
159 * "hasNext": false
160 * }
161 * }
162 */
163
Bulk restores all non-permanently deleted files of chosen types

This code is an example of a page on which a visitor chooses a media type (or types). All files of that type/those types in which have been (non-permanently) deleted are restored.

Copy Code
1/********************************************
2 * Backend code - bulk-restore-files.web.js *
3 *******************************************/
4import { Permissions, webMethod } from 'wix-web-module';
5import { files } from 'wix-media.v2';
6import { elevate } from 'wix-auth';
7
8export const restoreFiles = webMethod(Permissions.Anyone, async (mediaTypes) => {
9 let idList = []
10 try {
11 const options = {
12 mediaTypes: mediaTypes
13 };
14 const elevatedListDeletedFiles = elevate(files.listDeletedFiles)
15 const deletedFiles = await elevatedListDeletedFiles(options);
16
17 idList = deletedFiles.files.map((file) => {
18 return file._id
19 });
20 } catch (error) {
21 console.error(error);
22 }
23
24 try {
25 const elevatedBulkRestoreFilesFromTrashBin = elevate(files.bulkRestoreFilesFromTrashBin);
26 const restoredFiles = await elevatedBulkRestoreFilesFromTrashBin(idList);
27
28 console.log('Restored Files:', restoredFiles);
29 return restoredFiles;
30 } catch (error) {
31 console.error(error);
32 }
33});
34
35
36/*************
37 * Page code *
38 ************/
39
40import { restoreFiles } from 'backend/bulk-restore-files.web';
41
42$w.onReady(() => {
43 $w('#restoreMedia').onClick(async () => {
44 const mediaTypes = []
45 if ($w('#image').checked) {
46 mediaTypes.push("IMAGE")
47 }
48 if ($w('#video').checked) {
49 mediaTypes.push("VIDEO")
50 }
51 if ($w('#audio').checked) {
52 mediaTypes.push("AUDIO")
53 }
54 if ($w('#document').checked) {
55 mediaTypes.push("DOCUMENT")
56 }
57 if ($w('#vector').checked) {
58 mediaTypes.push("VECTOR")
59 }
60 if ($w('#archive').checked) {
61 mediaTypes.push("ARCHIVE")
62 }
63 if ($w('#model3d').checked) {
64 mediaTypes.push("MODEL3D")
65 }
66 await restoreFiles(mediaTypes);
67
68 $w('#filesRestoredMsg').show();
69 setTimeout(() => {
70 $w('#filesRestoredMsg').hide();
71 }, 5000);
72 });
73});