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

Copy Code
1/**************************************
2 * Page code *
3 **************************************/
4
5 import {myMoveFilesToTrashFunction, myListVideosFunction} from "backend/media";
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.jsw *
27 **************************************/
28import { mediaManager } from 'wix-media-backend';
29
30export function myListVideosFunction(filters) {
31 return mediaManager.listFiles(filters)
32 .then((myVideos) => {
33 return myVideos;
34 })
35 .catch((error) => {
36 console.error(error);
37 });
38}
39
40export function myMoveFilesToTrashFunction(fileUrls) {
41 return mediaManager.moveFilesToTrash(fileUrls)
42 .then(() => {
43 console.log('Success! Videos have been trashed.');
44 })
45 .catch((error) => {
46 console.error(error);
47 })
48}
49
50/**
51 * Returns a promise that resolves to <void>
52 **/