Is it possible to delete the files contained in the trash from code?

Hi everyone,
Is it possible to delete the files contained in the trash from code?
I saw that using wix-media.v2 the command: listDeletedFiles
it should list all the files in the trash.
It doesn’t work for me, it comes back

message: 'INVALID_ARGUMENT: ’
details:
validationError:
fieldViolations:

There are no examples, the documentation is rather weak.
Any example or solution is welcome.
Thank you

Can you share the code producing that error?

As for the question, wix-media.v2 lets you permanently delete files and skip the trash bulkDeleteFiles - Velo API Reference - Wix.com like so:

import { files } from 'wix-media.v2';
files.bulkDeleteFiles(fileIds, { permanent: true });

I’ve not tested if it will also permanently delete files that are already in the trash.

Edit: Note this code will not work as-is and you’ll need to also elevate the function to get it to run. The docs on doing this are available here: elevate - Velo API Reference - Wix.com

export async function GetIDFolder_TRASH() {
    let options = [{ mediaTypes: "IMAGE" }];
    console.log(options);
    try {
        const result = await files.listDeletedFiles(options);
        return result;
    } catch (error) {
        console.error(error);
        // Handle the error
    }
}

You’ll need to elevate the function in order to get it to work:

Hi Anthony,
I understand, in order to make everything ok, you need to raise the users to a high level. In the next few days, I’ll do some tests then I’ll update you. Thanks for now

Hi Anthony,
now it works for me. Thanks again for your support.

import { files } from ‘wix-media.v2’;
import * as wixAuth from ‘wix-auth’

export async function EmptyTrashFolder() {
try {
const myElevatedDeleteFiles = wixAuth.elevate(files.listDeletedFiles);
const result = await myElevatedDeleteFiles();
if (!ObjectIsEmpty(result)) {
var listFilestoTrash = ;
result.files.forEach(element => {
listFilestoTrash.push(element._id);
});

        const myElevatedbulkDeleteFiles = wixAuth.elevate(files.bulkDeleteFiles);
        await myElevatedbulkDeleteFiles(listFilestoTrash, { permanent: true });
    }
} catch (error) {
    console.error(error);
}

}

Hi Anthony,
what a spectacle the library: wix-media.v2 and especially the function: files.updateFileDescriptor.
You did a good job, congratulations to your team.

I solved the problem of the mediaManager.upload, which for a large amount of files to copy, because most of the time it doesn’t work or worse it doesn’t respond causing great frustration for me and my collaborators.

Thank you