Search.../

bulkRestoreFilesFromTrashBin( )

Developer Preview

Restores the specified files from the Media Manager's trash bin, and moves them to their original locations in the Media Manager.

Description

The bulkRestoreFilesFromTrashBin() function returns a Promise that resolves when the files have been restored.

Admin Method

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

Syntax

function bulkRestoreFilesFromTrashBin(fileIds: Array<string>): Promise<void>

bulkRestoreFilesFromTrashBin Parameters

NAME
TYPE
DESCRIPTION
fileIds
Array<
string
>

IDs of the files to restore from the Media Manager's trash bin.

Returns

Return Type:

Promise<
void
>

Was this helpful?

Bulk restore deleted files by IDs

Copy Code
1import { files } from 'wix-media.v2';
2import { elevate } from 'wix-auth';
3
4/* Sample fileIds value:
5 * [
6 * 'd4dde1_dee18c9ada174a818ccf75c50e72c739~mv2.jpg',
7 * 'd4dde1_32288e20a5aa4213a52b15426fb27c9f~mv2.png',
8 * 'd4dde1_8dd2bfe6121f43b29ebeaa63988abf54.svg'
9 * ]
10 */
11
12async function myBulkRestoreFilesFromTrashBinFunction(fileIds) {
13 try {
14 const elevatedBulkRestoreFilesFromTrashBin = elevate(files.bulkRestoreFilesFromTrashBin);
15 const restoredFiles = await elevatedBulkRestoreFilesFromTrashBin(fileIds);
16
17 console.log('Restored Files:', restoredFiles);
18 return restoredFiles;
19 } catch (error) {
20 console.error(error);
21 }
22}
23
24/* Promise resolves to void */
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});