Search.../

createFolder( )

Developer Preview

Creates a new folder in the Media Manager.

Description

The createFolder() function returns a Promise that resolves to the created folder.

Use the parentFolderId parameter to specify in which existing folder you want the new folder to be created. If no folder is specified, the new folder is created in the media-root folder.

Admin Method

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

Syntax

function createFolder(displayName: string, options: CreateFolderOptions): Promise<CreateFolderResponse>

createFolder Parameters

NAME
TYPE
DESCRIPTION
displayName
string

Folder name that appears in the Media Manager.

options
Optional
CreateFolderOptions

Options for specifying where to create a folder.

Returns

Return Type:

Promise<
CreateFolderResponse
>
NAME
TYPE
DESCRIPTION
folder
Folder

Information about the newly created folder.

Was this helpful?

Create a folder

Copy Code
1import { folders } from 'wix-media.v2';
2import { elevate } from 'wix-auth';
3
4
5/* Sample displayName value: 'Vector Art'
6 *
7 * Sample options value:
8 * {
9 * parentFolderId: 'b2bc72834460412494c93617d88b8c89'
10 * }
11 */
12
13async function myCreateFolderFunction(displayName, options) {
14 try {
15 const elevateCreateFolder = elevate(folders.createFolder);
16 const newFolder = await elevateCreateFolder(displayName, options);
17
18 console.log('Created folder successfully:', newFolder);
19 return newFolder;
20 } catch (err){
21 console.error(err);
22 // Handle the error
23 }
24}
25
26/* Promise resolves to:
27 * {
28 * "folder": {
29 * "_createdDate": "2023-08-14T08:05:03.000Z",
30 * "_id": "128833f888ea4846bbfbe8f164f3c6b5",
31 * "_updatedDate": "2023-08-14T08:05:03.000Z",
32 * "displayName": "Vector Art",
33 * "parentFolderId": "b2bc72834460412494c93617d88b8c89",
34 * "state": "OK"
35 * }
36 * }
37 */
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