Retrieves a list of files in the Media Manager.
The listFiles()
function returns a Promise that resolves to an array of the specified files' descriptors and cursor information.
To retrieve a list of files within a specific folder in the Media Manager, pass the folder's ID in the parentFolderId
parameter. If no folder is specified, the function retrieves only the files in the root folder of the Media Manager.
To retrieve a list of (non-permanently) deleted files, use the listDeletedFiles()
function.
This function requires elevated permissions and runs only on the backend and on dashboard pages.
function listFiles(options: ListFilesOptions): Promise<ListFilesResponse>;
Options to use when listing media files.
import { files } from "wix-media.v2";
import { elevate } from "wix-auth";
/* Sample listOptions value:
* {
* parentFolderId : 'igje5u22nij3qkltzsnol37j3dnthvvh'
* }
*/
async function myListFilesFunction(listOptions) {
try {
const elevatedListFiles = elevate(files.listFiles);
const fileList = await elevatedListFiles(listOptions);
console.log("Files in folder:", fileList);
return fileList;
} catch (error) {
console.error(error);
// Handle the error
}
}
/* Promise resolves to:
* {
* "files": [
* {
* "_createdDate": "2023-07-16T08:56:07.000Z",
* "_id": "w8ide0_f4dRFF610cKd7zkjVbaNddXgb181lXfg.pdf",
* "_updatedDate": "2023-07-16T08:56:07.000Z",
* "displayName": "file1.pdf",
* "hash": "z3bxokp79p04ok6iiu9ao8srx5lrynfh",
* "internalTags": [
* "_fileOrigin_uploaded"
* ],
* "labels": [],
* "media": {
* "document": "wix:document://v1/w8ide0_f4dRFF610cKd7zkjVbaNddXgb181lXfg.pdf/file1.pdf"
* },
* "mediaType": "DOCUMENT",
* "operationStatus": "READY",
* "parentFolderId": "igje5u22nij3qkltzsnol37j3dnthvvh",
* "private": false,
* "siteId": "3ecba886-4267-11ee-be56-0242ac120002",
* "sizeInBytes": "187199",
* "state": "OK",
* "thumbnailUrl": "https://static.wixstatic.com/media/it7ucst133nc8d9e0ff4d0nay1ucksc6.png",
* "url": "https://3ecba886-4267-11ee-be56-0242ac120002.usrfiles.com/ugd/w8ide0_f4dRFF610cKd7zkjVbaNddXgb181lXfg.pdf"
* },
* {
* "_createdDate": "2023-07-16T08:56:07.000Z",
* "_id": "w8ide0_170y03n3akmstnpt5jmsju89wvgs9tg4.pdf",
* "_updatedDate": "2023-07-16T08:56:07.000Z",
* "displayName": "file2.pdf",
* "hash": "g6x41coggaystn596ndb09q1ecg036gk",
* "internalTags": [
* "_fileOrigin_uploaded"
* ],
* "labels": [],
* "media": {
* "document": "wix:document://v1/w8ide0_170y03n3akmstnpt5jmsju89wvgs9tg4.pdf/file2.pdf"
* },
* "mediaType": "DOCUMENT",
* "operationStatus": "READY",
* "parentFolderId": "igje5u22nij3qkltzsnol37j3dnthvvh",
* "private": false,
* "siteId": "3ecba886-4267-11ee-be56-0242ac120002",
* "sizeInBytes": "81624",
* "state": "OK",
* "thumbnailUrl": "https://static.wixstatic.com/media/it7ucst133nc8d9e0ff4d0nay1ucksc6.png",
* "url": "https://3ecba886-4267-11ee-be56-0242ac120002.usrfiles.com/ugd/w8ide0_170y03n3akmstnpt5jmsju89wvgs9tg4.pdf"
* }
* ],
* "nextCursor": {
* "cursors": {
* "next": ""
* },
* "hasNext": false
* }
* }
*/
There are 2 errors with this status code.
This method may also return standard errors. Learn more about standard Wix errors.