Search.../

updateFolder( )

Developer Preview

Updates a folder.

Description

The updateFolder() function returns a Promise that resolves to information about the updated folder.

You can use the parentFolderId parameter to move a folder from its current parent folder to a different parent folder.

Admin Method

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

Syntax

function updateFolder(_id: string, folder: UpdateFolder): Promise<Folder>

updateFolder Parameters

NAME
TYPE
DESCRIPTION
_id
string

Folder ID. Generated when a folder is created in the Media Manager.

folder
UpdateFolder

Folder to update.

Returns

Information about the updated folder.

Return Type:

Promise<
Folder
>
NAME
TYPE
DESCRIPTION
_createdDate
Date

Date the folder was created.

_id
string

Folder ID. Generated when a folder is created in the Media Manager.

_updatedDate
Date

Date the folder was updated.

displayName
string

Folder name as it appears in the Media Manager.

parentFolderId
string

ID of the folder's parent folder.
Default: media-root folder.

state
string

State of the folder.

Supported values: "OK", "DELETED".

Was this helpful?

Update a folder's name

Copy Code
1import { folders } from 'wix-media.v2';
2import { elevate } from 'wix-auth';
3
4/* Sample id value: '7984b3c5454e4371aqbd4f4eedde96bc'
5 *
6 * Sample folder value:
7 * {
8 * displayName: 'mountains'
9 * }
10 */
11
12async function myUpdateFolderFunction(id, options) {
13 try {
14 const elevatedUpdateFolder = elevate(folders.updateFolder);
15 const updatedFolder = await elevatedUpdateFolder(id, options);
16
17 console.log(`Updated folder ${updatedFolder.displayName}:`, updatedFolder);
18 return updatedFolder;
19 } catch (error) {
20 console.error(error);
21 // Handle the error
22 }
23}
24
25/* Promise resolves to:
26 * {
27 * "_createdDate": "2023-08-21T09:32:34.000Z",
28 * "_id": "7984b3c5454e4371acbd4f4eedde96bc",
29 * "_updatedDate": "2023-08-21T11:10:51.000Z",
30 * "displayName": "mountains",
31 * "parentFolderId": "103601562ec94214bee61f470b403dd5",
32 * "state": "OK"
33 * }
34 */
Update a folder's location

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 updateFolder(id, options) {
20 try {
21 const elevatedUpdateFolder = elevate(folders.updateFolder);
22 const updatedFolder = await elevatedUpdateFolder(id, options);
23
24 return updatedFolder;
25 } catch (error) {
26 console.error(error);
27 }
28}
29
30/*************
31 * Page code *
32 ************/
33
34import { updateFolder, listFolders } from 'backend/create-folder';
35
36$w.onReady(async () => {
37 await populateFoldersDropdowns();
38
39 $w('#updateFolderLocation').onClick(async () => {
40 const folderId = $w('#updateFolderDropdown').value;
41 const parentFolderId = $w('#parentFolderDropdown').value;
42 if (folderId === parentFolderId) {
43 $w('#folderIsParentFolderMsg').show();
44 return;
45 };
46 const options = {parentFolderId};
47 const updatedFolder = await updateFolder(folderId, options);
48
49 console.log(`Successfully updated folder ${updatedFolder.displayName}:`, updatedFolder);
50 $w('#updateFolderSuccessMsg').show();
51 });
52});
53
54async function populateFoldersDropdowns() {
55 const folders = await listFolders();
56 const dropdownOptions = folders.map((folder) => {
57 return {
58 label: folder.displayName,
59 value: folder._id
60 };
61 });
62
63 $w('#updateFolderDropdown').options = dropdownOptions;
64 $w('#parentFolderDropdown').options = dropdownOptions;
65};
66