Search.../

listFiles( )

Gets a list of files from the Media Manager by parentFolderId (or root).

Description

The listFiles() function returns a Promise that resolves to information about the files in the folder.

To get 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 listFiles() function returns the list of files in the root folder of the Media Manager.

Notes:

  • This function's parameters are positional, and must be specified in the sequence shown in the syntax below. When specifying a parameter, use null as a placeholder for any unspecified parameters. For example, to specify parentFolderId only, call listFiles(filters, null, null). For example, to specify sorting only, call listFiles(null, sorting, null).

  • The listFiles() function only gets a list of files with supported media types, and that are explicitly listed in the Media Manager. Files with unsupported media types such as 'model', and files that aren't explicitly listed in the Media Manager such as default files in a gallery component, aren't listed when calling the listFiles() function. The supported media types are listed in the description for the mediaType return in the getFileInfo() function.

Syntax

function listFiles([filters: FileFilterOptions], [sorting: SortingOptions], [paging: PagingOptions]): File

listFiles Parameters

NAME
TYPE
DESCRIPTION
filters
Optional
FileFilterOptions

File filter options.

sorting
Optional
SortingOptions

Sorting options.

paging
Optional
PagingOptions

Paging options.

Returns

Fulfilled - Information about the files.

Return Type:

Promise<Array<File>>
NAME
TYPE
DESCRIPTION
fileName
string

Deprecated. Use the fileUrl property instead.

The fileName property is the internal name (unique identifier) which is generated when a file is uploaded by the Media Manager, returned from the importFile(), or upload() functions. The name is the string located in the file's URL. Click here to learn more. Use this name when calling the getFileInfo(), getFileUrl(), and getVideoPlaybackUrl() functions.

fileUrl
string

The file's Wix media URL in the following format: 'wix:image://v1/<uri>/<filename>#originWidth=<width>&originHeight=<height>[&watermark=<watermark_manifest_string>]'.

hash
string

File hash.

sizeInBytes
number

Size of the listed file in bytes.

mimeType
string

Mime type of the listed file.

mediaType
string

Media type of the listed file. One of:

  • "audio"
  • "document"
  • "image"
  • "shape"
  • "video"
isPrivate
boolean

Whether the link to the listed file is public or private. Private links require a token to be used.

parentFolderId
string

ID of the file's parent folder.

originalFileName
string

Original name of the uploaded file. This is the display name that appears in the Media Manager.

iconUrl
string

URL of the file's icon.

labels
Array<string>

List of labels assigned to the file by the Media Manager.

height
string

Media height.

width
string

Media width.

_createdDate
Date

Date the file was created.

_updatedDate
Date

Date the file was updated.

Was this helpful?

List files in a specified folder

Copy Code
1import { Permissions, webMethod } from 'wix-web-module';
2import { mediaManager } from 'wix-media-backend';
3
4const filters = {
5 parentFolderId: "8a3be85ea03e4b8b82f2f9c989557c3d"
6};
7
8export const myListFilesFunction = webMethod(Permissions.Anyone, () => {
9 return mediaManager.listFiles(filters, null, null)
10 .then((myFiles) => {
11 const originalFileName = myFiles[0].originalFileName;
12 const fileUrl = myFiles[1].fileUrl;
13 return myFiles;
14 })
15 .catch((error) => {
16 console.error(error);
17 });
18});
19
20/* Returns a promise that resolves to:
21 * [{
22 * "fileUrl": "wix:image://v1/f6c0f9_tg439f4475a749e181dd14407fdbd37e~mv2.jpg/original-name.jpg#originWidth=300&originHeight=300",
23 * "hash": "Ew00kXbu4Zt33rzjcWa6Ng==",
24 * "sizeInBytes": 51085,
25 * "mimeType": "image/jpeg",
26 * "mediaType": "image",
27 * "isPrivate": false,
28 * "iconUrl": "wix:image://v1/f6c0f9_tg439f4475a749e181dd14407fdbd37e~mv2.jpg/original-name.jpg#originWidth=300&originHeight=300",
29 * "parentFolderId": "8a3be85ea03e4b8b82f2f9c989557c3d",
30 * "originalFileName": "original-name1.jpg",
31 * "width": 300,
32 * "height": 300,
33 * "labels": [
34 * "Blue",
35 * "Butterfly",
36 * "Turquoise"
37 * ],
38 * "_createdDate": "Sun December 4 2020 10:56:09 GMT+0300",
39 * "_updatedDate": "Wed May 12 2021 14:27:15 GMT+0300"
40 * },
41 * {
42 * "fileUrl": "wix:image://v1/8b7eef_47332c4ae5b74db89d86d5d9e0cd303b~mv2.png/Screen%20Shot%202021-05-19%20at%209.59.29.png#originWidth=984&originHeight=1230",
43 * "hash": "93fea6d1c6f7b10e24a729b0402ac152",
44 * "sizeInBytes": 232794,
45 * "mimeType": "image/jpeg",
46 * "mediaType": "image",
47 * "isPrivate": false,
48 * "iconUrl": "wix:image://v1/8b7eef_47332c4ae5b74db89d86d5d9e0cd303b~mv2.png/Screen%20Shot%202021-05-19%20at%209.59.29.png#originWidth=984&originHeight=1230",
49 * "parentFolderId": "8a3be85ea03e4b8b82f2f9c989557c3d",
50 * "originalFileName": "original-name2.jpg",
51 * "sourceUrl": "https://somedomain.com/img/original-name.jpg",
52 * "width": 984,
53 * "height": 221,
54 * "labels": [
55 * "Font",
56 * "Type",
57 * "Write"
58 * ],
59 * "opStatus": "READY",
60 * "_createdDate": "Tues January 22 2020 12:56:02 GMT+0300",
61 * "_updatedDate": "Fri October 9 2020 04:56:22 GMT+0300"
62 * }]
63 */
List files in the root folder

Copy Code
1import { Permissions, webMethod } from 'wix-web-module';
2import { mediaManager } from 'wix-media-backend';
3
4export const myListFilesFunction = webMethod(Permissions.Anyone, () => {
5 return mediaManager.listFiles()
6 .then((myFiles) => {
7 const originalFileName = myFiles[0].originalFileName;
8 const fileUrl = myFiles[0].fileUrl;
9 return myFiles;
10 })
11 .catch((error) => {
12 console.error(error);
13 });
14});
15
16
17/* Returns a promise that resolves to:
18 * [{
19 * "fileUrl": "wix:image://v1/g9c0f9_tg422f4475a749e661dd14407fdbd37k~mv2.jpg/original-name.jpg#originWidth=300&originHeight=300",
20 * "hash": "Pq00kXbvu4Zt3239rzjcWa6Ng==",
21 * "sizeInBytes": 23746,
22 * "mimeType": "image/jpeg",
23 * "mediaType": "image",
24 * "isPrivate": false,
25 * "iconUrl": "wix:image://v1/g9c0f9_tg422f4475a749e661dd14407fdbd37k~mv2.jpg/original-name.jpg#originWidth=300&originHeight=300",
26 * "parentFolderId": "media-root",
27 * "originalFileName": "original-name.jpg",
28 * "width": 220,
29 * "height": 340,
30 * "labels": [
31 * "Sand",
32 * "Beach"
33 * ],
34 * "_createdDate": "Mon September 2 2019 13:56:06 GMT+0300",
35 * "_updatedDate": "Sat June 20 2020 14:33:07 GMT+0300"
36 * }]
37 */
Filter, sort, and paginate a list of files

In this example we list image files in a specified folder that are public, and sort them in ascending alphabetical order according to the original file name. We skip the first file in the list and limit the result to the next 3 files in the list.

Copy Code
1
2import { Permissions, webMethod } from 'wix-web-module';
3import { mediaManager } from 'wix-media-backend';
4
5const filters = {
6 parentFolderId: "9162670cf5434db787bdd9715b46b473",
7 mediaType: "image",
8 isPrivate: false
9};
10
11const sorting = {
12 order: "asc",
13 field: "originalFileName"
14};
15
16const paging = {
17 limit: 3,
18 skip: 1
19};
20
21export const myListFilesFunction = webMethod(Permissions.Anyone, () => {
22 return mediaManager.listFiles(filters, sorting, paging)
23 .then((myFiles) => {
24 const originalFileName = myFiles[0].originalFileName;
25 const fileUrl = myFiles[1].fileUrl;
26 return myFiles;
27 })
28 .catch((error) => {
29 console.error(error);
30 });
31});
32
33
34/* Returns a promise that resolves to:
35 * [{
36 * "fileUrl": "wix:image://v1/p0c0f9_tg439f4475a749e181dd14407fdbd99e~mv2.~mv2.jpg/original-name.jpg#originWidth=300&originHeight=300",
37 * "hash": "Ew00kXbu4Zt33rzjcWa6Ng==",
38 * "sizeInBytes": 51085,
39 * "mimeType": "image/jpeg",
40 * "mediaType": "image",
41 * "isPrivate": false,
42 * "iconUrl": "wix:image://v1/p0c0f9_tg439f4475a749e181dd14407fdbd99e~mv2.~mv2.jpg/original-name.jpg#originWidth=300&originHeight=300",
43 * "parentFolderId": "9162670cf5434db787bdd9715b46b473",
44 * "originalFileName": "apple.jpg",
45 * "width": 300,
46 * "height": 300,
47 * "labels": [
48 * "Green",
49 * "Tree",
50 * "Worm"
51 * ],
52 * "_createdDate": "Mon October 5 2018 14:26:27 GMT+0300",
53 * "_updatedDate": "Wed May 12 2021 11:12:45 GMT+0300"
54 * },
55 * {
56 * "fileUrl": "wix:image://v1/qr7eef_47332c4ae5b74db89d86d5d9e0cd303b~mv2.png/Screen%20Shot%202021-05-19%20at%209.59.29.png#originWidth=984&originHeight=1230",
57 * "hash": "93fea6d1c6f7b10e24a729b0402ac152",
58 * "sizeInBytes": 232794,
59 * "mimeType": "image/jpeg",
60 * "mediaType": "image",
61 * "isPrivate": false,
62 * "iconUrl": "wix:image://v1/qr7eef_47332c4ae5b74db89d86d5d9e0cd303b~mv2.png/Screen%20Shot%202021-05-19%20at%209.59.29.png#originWidth=984&originHeight=1230",
63 * "parentFolderId": "9162670cf5434db787bdd9715b46b473",
64 * "originalFileName": "banana.jpg",
65 * "sourceUrl": "https://somedomain.com/img/original-name.jpg",
66 * "width": 984,
67 * "height": 221,
68 * "labels": [
69 * "Yellow",
70 * "Peel"
71 * ],
72 * "opStatus": "READY",
73 * "_createdDate": "Sun February 04 2016 02:29:07 GMT+0300",
74 * "_updatedDate": "Fri October 9 2020 09:33:22 GMT+0300"
75 * },
76 * {
77 * "fileUrl": "wix:image://v1/nm8ttl_47332c4ae5b74db89d86d5d9e0cd303b~mv2.png/Screen%20Shot%202021-05-19%20at%209.59.29.png#originWidth=984&originHeight=1230",
78 * "hash": "93fea6d1c6f7b10e24a729b0402ac152",
79 * "sizeInBytes": 122794,
80 * "mimeType": "image/jpeg",
81 * "mediaType": "image",
82 * "isPrivate": false,
83 * "iconUrl": "wix:image://v1/nm8ttl_47332c4ae5b74db89d86d5d9e0cd303b~mv2.png/Screen%20Shot%202021-05-19%20at%209.59.29.png#originWidth=984&originHeight=1230",
84 * "parentFolderId": "9162670cf5434db787bdd9715b46b473",
85 * "originalFileName": "cherry.jpg",
86 * "width": 200,
87 * "height": 400,
88 * "labels": [
89 * "Red",
90 * "Stem"
91 * ],
92 * "_createdDate": "Tues January 22 2019 12:56:02 GMT+0300",
93 * "_updatedDate": "Thurs March 11 2021 05:44:20 GMT+0300"
94 * }]
95 */
96