Search.../

listFolders( )

Developer Preview

Retrieves a list of folders in the Media Manager.

Description

The listFolders() function returns a Promise that resolves to information about the specified folders and cursor information.

To retrieve a list of folders within a specific folder in the Media Manager, pass the specific folder's ID in the parentFolderId parameter. If no folder is specified, the endpoint retrieves only the list of folders within the root folder of the Media Manager.

To retrieve a list of (non-permanently) deleted folders, use the listDeletedFolders() function.

Admin Method

This function requires elevated permissions to run. This function is not universal and runs only on the backend.

Syntax

function listFolders(options: ListFoldersOptions): Promise<ListFoldersResponse>

listFolders Parameters

NAME
TYPE
DESCRIPTION
options
Optional
ListFoldersOptions

Options to use when listing folders from the Media Manager.

Returns

Return Type:

Promise<
ListFoldersResponse
>
NAME
TYPE
DESCRIPTION
folders
Array<
Folder
>

Information about the folders in the requested folder.

nextCursor
PagingMetadataV2

The next cursor if it exists.

Was this helpful?

List folders

Copy Code
1import { folders } from 'wix-media.v2';
2import { elevate } from 'wix-auth';
3
4async function myListFoldersFunction()
5{
6 try {
7 const elevatedListFolders = elevate(folders.listFolders);
8 const folders = await elevatedListFolders();
9
10 console.log("Folders:", folders);
11 return folders;
12 } catch (error) {
13 console.error(error);
14 // Handle the error
15 }
16}
17
18/* Promise resolves to:
19 * {
20 * "folders": [
21 * {
22 * "_createdDate": "2023-08-14T07:41:19.000Z",
23 * "_id": "103601562ec94214bee61f470b403dd5",
24 * "_updatedDate": "2023-08-14T07:41:19.000Z",
25 * "displayName": "Pictures",
26 * "parentFolderId": "media-root",
27 * "state": "OK"
28 * },
29 * {
30 * "_createdDate": "2023-08-14T07:38:31.000Z",
31 * "_id": "c956d69906414e7faf8a0ad81117b17d",
32 * "_updatedDate": "2023-08-14T07:38:31.000Z",
33 * "displayName": "Videos",
34 * "parentFolderId": "media-root",
35 * "state": "OK"
36 * },
37 * {
38 * "_createdDate": "2023-08-09T08:57:12.000Z",
39 * "_id": "b2bc72834460412494c93617d88b8c89",
40 * "_updatedDate": "2023-08-09T08:57:12.000Z",
41 * "displayName": "Documents",
42 * "parentFolderId": "media-root",
43 * "state": "OK"
44 * }
45 * ],
46 * "nextCursor": {
47 * "cursors": {
48 * "next": ""
49 * },
50 * "hasNext": false
51 * }
52 * }
53 */
List 5 folders found in a parent folder, sorted alphabetically by name

Copy Code
1import { folders } from 'wix-media.v2';
2import { elevate } from 'wix-auth';
3
4/* Sample options value:
5 * {
6 * paging: {
7 * limit: 5
8 * },
9 * parentFolderId : '103601562ec94214bee61f470b403dd5',
10 * sort : {
11 * fieldName : 'displayName',
12 * order : 'ASC'
13 * }
14 * }
15 */
16
17async function myListFoldersFunction(options)
18{
19 try {
20 const result = await folders.listFolders(options);
21
22 const folderList = result.folders;
23
24 folderList.forEach(element => {
25 console.log(element.displayName);
26 });
27
28 return result;
29 } catch (error) {
30 console.error(error);
31 // Handle the error
32 }
33}
34
35/* Promise resolves to:
36 * {
37 * "folders": [
38 * {
39 * "_createdDate": "2023-08-21T09:33:47.000Z",
40 * "_id": "0cfdf68ac3b9453b81cfe171caf40b0c",
41 * "_updatedDate": "2023-08-21T09:33:47.000Z",
42 * "displayName": "31-08",
43 * "parentFolderId": "103601562ec94214bee61f470b403dd5",
44 * "state": "OK"
45 * },
46 * {
47 * "_createdDate": "2023-08-21T09:33:30.000Z",
48 * "_id": "193161aeef8f4b80b97d7032fb2c4f0a",
49 * "_updatedDate": "2023-08-21T11:09:58.000Z",
50 * "displayName": "Water",
51 * "parentFolderId": "103601562ec94214bee61f470b403dd5",
52 * "state": "OK"
53 * },
54 * {
55 * "_createdDate": "2023-08-21T09:32:39.000Z",
56 * "_id": "4b9e2dd061de4f3e80e3ada23b0fb440",
57 * "_updatedDate": "2023-08-21T09:32:39.000Z",
58 * "displayName": "city",
59 * "parentFolderId": "103601562ec94214bee61f470b403dd5",
60 * "state": "OK"
61 * },
62 * {
63 * "_createdDate": "2023-08-21T09:56:43.000Z",
64 * "_id": "6a86df2ce32c4d279c21fbdd2887c18b",
65 * "_updatedDate": "2023-08-21T09:56:43.000Z",
66 * "displayName": "docs1",
67 * "parentFolderId": "103601562ec94214bee61f470b403dd5",
68 * "state": "OK"
69 * },
70 * {
71 * "_createdDate": "2023-08-21T09:33:10.000Z",
72 * "_id": "5d0625ed28494bf7938c03e9a21130ba",
73 * "_updatedDate": "2023-08-21T09:33:24.000Z",
74 * "displayName": "docs2",
75 * "parentFolderId": "103601562ec94214bee61f470b403dd5",
76 * "state": "OK"
77 * },
78 * {
79 * "_createdDate": "2023-08-21T09:32:34.000Z",
80 * "_id": "7984b3c5454e4371acbd4f4eedde96bc",
81 * "_updatedDate": "2023-08-21T11:10:51.000Z",
82 * "displayName": "mountains",
83 * "parentFolderId": "103601562ec94214bee61f470b403dd5",
84 * "state": "OK"
85 * }
86 * ],
87 * "nextCursor": {
88 * "cursors": {
89 * "next": ""
90 * },
91 * "hasNext": false
92 * }
93 * }
94 */
Create a folder from visitor input

This code is an example of a page on which a visitor chooses a folder from a dropdown list, and then creates a folder within that folder.

Copy Code
1/************************************
2 * Backend code - create-folder.jsw *
3 ***********************************/
4
5import { folders } from 'wix-media.v2';
6import { elevate } from 'wix-auth';
7
8export async function listFolders() {
9 try {
10 const elevatedListFolders = elevate(folders.listFolders)
11 const foldersList = await elevatedListFolders();
12
13 return foldersList;
14 } catch (error) {
15 console.error(error);
16 }
17}
18
19async function createFolder(displayName, options) {
20 try {
21 const elevateCreateFolder = elevate(folders.createFolder);
22 const newFolder = await elevateCreateFolder(displayName, options);
23
24 return newFolder;
25 } catch (err){
26 console.error(err);
27 }
28}
29
30/*************
31 * Page code *
32 ************/
33
34import { createFolder, listFolders } from 'backend/create-folder';
35
36$w.onReady(async () => {
37 await populateFoldersDropdown();
38
39 $w('#createFolder').onClick(async () => {
40 const folderName = $w('folderName').value;
41 const createOptions = {parentFolderId: $w('foldersDropdown').value};
42 const newFolder = await createFolder(folderName, createOptions);
43
44 console.log(`Successfully created new folder "${folderName}" in ${$w('#foldersDropdown').label}.`)
45 $w('#createdFolderSuccessMsg').show();
46 });
47});
48
49async function populateFoldersDropdown() {
50 const folders = await listFolders();
51 const dropdownOptions = folders.map((folder) => {
52 return {
53 label: folder.displayName,
54 value: folder._id
55 };
56 });
57
58 $w('#foldersDropdown').options = dropdownOptions;
59};
60