Search.../

listDeletedFiles( )

Developer Preview

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

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

Copy Code
1import { files } from 'wix-media.v2';
2import { elevate } from 'wix-auth';
3
4/* Sample options value:
5 * {
6 * paging: {
7 * limit: 2
8 * },
9 * sort: {
10 * order: 'ASC'
11 * }
12 * }
13 */
14
15async function listDeletedFiles(options) {
16 try {
17 const elevatedListDeletedFiles = elevate(files.listDeletedFiles)
18 const deletedFiles = await elevatedListDeletedFiles(options);
19
20 console.log('Files in trash:', deletedFiles)
21 return deletedFiles;
22 } catch (error) {
23 console.error(error);
24 // Handle the error
25 }
26}
27
28/* Promise resolves to:
29 * {
30 * "files": [
31 * {
32 * "_createdDate": "2023-08-09T08:45:42.000Z",
33 * "_id": "d4dde1_32288e20a5aa4213a52b15426fb27c9f~mv2.png",
34 * "_updatedDate": "2023-08-09T08:45:42.000Z",
35 * "displayName": "IMG1.png",
36 * "hash": "864d607a1ea270efbac32def181f039f",
37 * "internalTags": [
38 * "_fileOrigin_uploaded"
39 * ],
40 * "labels": [],
41 * "media": {
42 * "image": {
43 * "colors": {
44 * "palette": [
45 * {
46 * "rgb": {
47 * "b": 247,
48 * "g": 247,
49 * "r": 247
50 * }
51 * },
52 * {
53 * "rgb": {
54 * "b": 142,
55 * "g": 140,
56 * "r": 140
57 * }
58 * },
59 * {
60 * "rgb": {
61 * "b": 192,
62 * "g": 218,
63 * "r": 141
64 * }
65 * },
66 * {
67 * "rgb": {
68 * "b": 195,
69 * "g": 137,
70 * "r": 149
71 * }
72 * },
73 * {
74 * "rgb": {
75 * "b": 228,
76 * "g": 143,
77 * "r": 183
78 * }
79 * },
80 * {
81 * "rgb": {
82 * "b": 250,
83 * "g": 62,
84 * "r": 152
85 * }
86 * },
87 * {
88 * "rgb": {
89 * "b": 16,
90 * "g": 16,
91 * "r": 16
92 * }
93 * },
94 * {
95 * "rgb": {
96 * "b": 140,
97 * "g": 199,
98 * "r": 60
99 * }
100 * },
101 * {
102 * "rgb": {
103 * "b": 120,
104 * "g": 194,
105 * "r": 242
106 * }
107 * },
108 * {
109 * "rgb": {
110 * "b": 158,
111 * "g": 203,
112 * "r": 103
113 * }
114 * }
115 * ],
116 * "prominent": {
117 * "rgb": {
118 * "b": 247,
119 * "g": 247,
120 * "r": 247
121 * }
122 * }
123 * },
124 * "faces": [],
125 * "image": "wix:image://v1/d4dde1_32288e20a5aa4213a52b15426fb27c9f~mv2.png/IMG1.png#originWidth=1170&originHeight=2532"
126 * }
127 * },
128 * "mediaType": "IMAGE",
129 * "operationStatus": "READY",
130 * "parentFolderId": "trash-root",
131 * "private": false,
132 * "siteId": "3ecba886-4267-11ee-be56-0242ac120002",
133 * "sizeInBytes": "394945",
134 * "state": "OK",
135 * "thumbnailUrl": "https://static.wixstatic.com/media/d4dde1_32288e20a5aa4213a52b15426fb27c9f~mv2.png",
136 * "url": "https://static.wixstatic.com/media/d4dde1_32288e20a5aa4213a52b15426fb27c9f~mv2.png"
137 * },
138 * {
139 * "_createdDate": "2023-08-09T08:45:37.000Z",
140 * "_id": "d4dde1_8dd2bfe6121f43b29ebeaa63988abf54.svg",
141 * "_updatedDate": "2023-08-09T08:45:37.000Z",
142 * "displayName": "vectorArt1c.svg",
143 * "hash": "e379083c3675d7f7891da00c0708539c",
144 * "internalTags": [
145 * "_fileOrigin_uploaded"
146 * ],
147 * "labels": [],
148 * "media": {
149 * "image": {
150 * "faces": [],
151 * "image": "wix:image://v1/d4dde1_8dd2bfe6121f43b29ebeaa63988abf54.svg/vectorArt1c.svg#originWidth=1177&originHeight=2501"
152 * }
153 * },
154 * "mediaType": "VECTOR",
155 * "operationStatus": "READY",
156 * "parentFolderId": "trash-root",
157 * "private": false,
158 * "siteId": "3ecba886-4267-11ee-be56-0242ac120002",
159 * "sizeInBytes": "119475",
160 * "state": "OK",
161 * "thumbnailUrl": "https://static.wixstatic.com/shapes/d4dde1_8dd2bfe6121f43b29ebeaa63988abf54.svg",
162 * "url": "https://static.wixstatic.com/shapes/d4dde1_8dd2bfe6121f43b29ebeaa63988abf54.svg"
163 * }
164 * ],
165 * "nextCursor": {
166 * "cursors": {
167 * "next": ""
168 * },
169 * "hasNext": false
170 * }
171 * }
172 */
173
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.jsw *
3 ****************************************/
4import { files } from 'wix-media.v2';
5import { elevate } from 'wix-auth';
6
7async function restoreFiles(mediaTypes) {
8 let idList = []
9 try {
10 const options = {
11 mediaTypes: mediaTypes
12 };
13 const elevatedListDeletedFiles = elevate(files.listDeletedFiles)
14 const deletedFiles = await elevatedListDeletedFiles(options);
15
16 idList = deletedFiles.files.map((file) => {
17 return file._id
18 });
19 } catch (error) {
20 console.error(error);
21 }
22
23 try {
24 const elevatedBulkRestoreFilesFromTrashBin = elevate(files.bulkRestoreFilesFromTrashBin);
25 const restoredFiles = await elevatedBulkRestoreFilesFromTrashBin(idList);
26
27 console.log('Restored Files:', restoredFiles);
28 return restoredFiles;
29 } catch (error) {
30 console.error(error);
31 }
32}
33
34
35/*************
36 * Page code *
37 ************/
38
39import { restoreFiles } from 'backend/bulk-import-files';
40
41$w.onReady(() => {
42 $w('#restoreMedia').onClick(async () => {
43 const mediaTypes = []
44 if ($w('#image').checked) {
45 mediaTypes.push("IMAGE")
46 }
47 if ($w('#video').checked) {
48 mediaTypes.push("VIDEO")
49 }
50 if ($w('#audio').checked) {
51 mediaTypes.push("AUDIO")
52 }
53 if ($w('#document').checked) {
54 mediaTypes.push("DOCUMENT")
55 }
56 if ($w('#vector').checked) {
57 mediaTypes.push("VECTOR")
58 }
59 if ($w('#archive').checked) {
60 mediaTypes.push("ARCHIVE")
61 }
62 if ($w('#model3d').checked) {
63 mediaTypes.push("MODEL3D")
64 }
65 await restoreFiles(mediaTypes);
66
67 $w('#filesRestoredMsg').show();
68 setTimeout(() => {
69 $w('#filesRestoredMsg').hide();
70 }, 5000);
71 });
72});