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';23/* Sample fileUrls array:4 * [5 * 'https://static.wixstatic.com/media/4c47c6_85e8701ae75d4bb48436aecbd28dda5a~mv2.png',6 * 'https://static.wixstatic.com/media/4c47c6_49b0e6d2c19b4564a191f88f6748bbb3~mv2.png'7 * ]8 */910export 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}1920/**21 * Returns a promise that resolves to <void>22 **/
Move video files to trash
Copy Code
1/**************************************2 * Page code *3 **************************************/45 import {myMoveFilesToTrashFunction, myListVideosFunction} from "backend/media";67 $w.onReady(function () {89 // ...1011 const filters = {12 mediaType: 'video'13 };1415 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});2425/**************************************26 * Backend code - media.jsw *27 **************************************/28import { mediaManager } from 'wix-media-backend';2930export function myListVideosFunction(filters) {31 return mediaManager.listFiles(filters)32 .then((myVideos) => {33 return myVideos;34 })35 .catch((error) => {36 console.error(error);37 });38}3940export 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}4950/**51 * Returns a promise that resolves to <void>52 **/