Search.../

moveFilesToTrash( )

Moves single or multiple files to the Media Manager's trash.

Description

The moveFilesToTrash() function returns a Promise that resolves when the file(s) are moved to the Media Manager's trash.

Moving many files to trash at once is an asynchronous action. It may take some time for the results to be seen in the Media Manager.

Use the Media Manager to restore or permanently delete the trashed files.

Attempting to move already-trashed files to trash again doesn't result in an error.

Syntax

function moveFilesToTrash(fileUrls: Array<string>): Promise<void>

moveFilesToTrash Parameters

NAME
TYPE
DESCRIPTION
fileUrls
Array<string>

URLs of the files to move to trash.

Returns

Return Type:

Promise<void>

Was this helpful?

Move a single file to trash

Copy Code
1import { Permissions, webMethod } from 'wix-web-module';
2import { mediaManager } from 'wix-media-backend';
3
4/* Sample fileUrls array:
5 * [
6 * "wix:image://v1/4c47c6_85e8701ae75d4bb48436aecbd28dda5a~mv2.png/cat8.png#originWidth=337&originHeight=216",
7 * "wix:image://v1/4c47c6_49b0e6d2c19b4564a191f88f6748bbb3~mv2.png/cat9.png#originWidth=319&originHeight=206"
8 * ]
9 */
10
11export const myMoveFilesToTrashFunction = webMethod(Permissions.Anyone, (fileUrls) => {
12 return mediaManager.moveFilesToTrash(fileUrls)
13 .then(() => {
14 console.log('Success! Files have been trashed.');
15 })
16 .catch((error) => {
17 console.error(error);
18 })
19});
20
21/**
22 * Returns a promise that resolves to <void>
23 **/
Move video files to trash

Copy Code
1/**************************************
2 * Page code *
3 **************************************/
4
5import { mediaManager } from 'wix-media-backend';
6
7$w.onReady(function () {
8
9 // ...
10
11 const filters = {
12 mediaType: 'video'
13 };
14
15 myListVideosFunction(filters)
16 .then((myVideos) => {
17 const fileUrls = myVideos.map(file => file.fileUrl);
18 myMoveFilesToTrashFunction(fileUrls);
19 })
20 .catch((error) => {
21 console.error(error);
22 });
23});
24
25/**************************************
26 * Backend code - media.web.js *
27 **************************************/
28import { Permissions, webMethod } from 'wix-web-module';
29import { mediaManager } from 'wix-media-backend';
30
31export const myListVideosFunction = webMethod(Permissions.Anyone, async (filters) => {
32 try {
33 const myVideos = await mediaManager.listFiles(filters);
34 return myVideos;
35 } catch (error) {
36 console.error(error);
37 }
38});
39
40export const myMoveFilesToTrashFunction = webMethod(Permissions.Anyone, async (fileUrls) => {
41 try {
42 await mediaManager.moveFilesToTrash(fileUrls);
43 console.log('Success! Videos have been trashed.');
44 } catch (error) {
45 console.error(error);
46 }
47});
48
49/**
50 * Returns a promise that resolves to <void>
51 **/