Search.../

updateFileDescriptor( )

Updates a file.

Description

The updateFileDescriptor() function returns a Promise that resolves to the updated file's descriptor.

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

Admin Method

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

Syntax

function updateFileDescriptor(_id: string, file: UpdateFileDescriptorFile): Promise<FileDescriptor>

updateFileDescriptor Parameters

NAME
TYPE
DESCRIPTION
_id
string

File ID. Generated when a file is uploaded to the Media Manager.

file
UpdateFileDescriptorFile

Returns

Information about the updated file.

Return Type:

Promise<
FileDescriptor
>
NAME
TYPE
DESCRIPTION
_createdDate
Date

Date and time the file was created.

_id
string

File ID. Generated when a file is uploaded to the Media Manager.

_updatedDate
Date

Date and time the file was updated.

displayName
string

File name as it appears in the Media Manager.

hash
string

File hash.

labels
Array<
string
>

Labels assigned to media files that describe and categorize them. Provided by the user, or generated by Google Vision API for images.

media
FileMedia

Media file content.

mediaType
string

Media file type.

Supported values: "IMAGE", "VIDEO", "AUDIO", "DOCUMENT", "VECTOR", "ARCHIVE", "MODEL3D"

operationStatus
string

Status of the file that was uploaded.

Supported values: "FAILED", "READY", "PENDING"

  • FAILED: The file failed to upload, for example, during media post processing.
  • READY: The file uploaded, finished all processing, and is ready for use.
  • PENDING: The file is processing and the URLs are not yet available. This response is returned when importing a file.
parentFolderId
string

ID of the file's parent folder.

private
boolean

Whether the link to the uploaded file is public or private. Private links require a token.

siteId
string

The Wix site ID where the media file is stored.

sizeInBytes
string

Size of the uploaded file in bytes.

sourceUrl
string

URL where the file was uploaded from.

state
string

State of the file.

Supported values: "OK", "DELETED"

thumbnailUrl
string

URL of the file's thumbnail.

url
string

Static URL of the file.

Was this helpful?

Update a file's location (dashboard page code)

Copy Code
1import { files } from 'wix-media.v2';
2
3/* Sample id value: 'd4dde1_0c8b26126ba94f3daee16d9e9be04f0c~mv2.jpg'
4 *
5 * Sample file value:
6 * {
7 * parentFolderId: 'b2bc72834460412494c93617d88b8c89'
8 * }
9 */
10
11async function myUpdateFileDescriptorFunction(id, file) {
12 try {
13 const updatedDescriptor = await files.updateFileDescriptor(id, file);
14
15 console.log("Updated:", updatedDescriptor);
16 return updatedDescriptor;
17 } catch (error) {
18 console.error(error);
19 // Handle the error
20 }
21}
22
23/* Promise resolves to:
24 * {
25 * "_createdDate": "2023-08-09T08:45:50.000Z",
26 * "_id": "d4dde1_0c8b26126ba94f3daee16d9e9be04f0c~mv2.jpg",
27 * "_updatedDate": "2023-09-10T09:53:50.000Z",
28 * "displayName": "river.jpg",
29 * "hash": "2f2a61275002b90e6e8fa1be4674c4a7",
30 * "internalTags": [
31 * "_fileOrigin_uploaded"
32 * ],
33 * "labels": [
34 * "mountain stream",
35 * "clear stream",
36 * "flowing water",
37 * "mountain torrent",
38 * "free-flowing",
39 * "streams",
40 * "running water",
41 * "downstream",
42 * "watercourse",
43 * "stream",
44 * "riverbed",
45 * "freshwater",
46 * "landscape photograph",
47 * "motion blur",
48 * "fresh water",
49 * "river bank",
50 * "torrent",
51 * "flow into",
52 * "landscape photography",
53 * "natural scenery"
54 * ],
55 * "media": {
56 * "image": {
57 * "colors": {
58 * "palette": [
59 * {
60 * "rgb": {
61 * "b": 41,
62 * "g": 41,
63 * "r": 24
64 * }
65 * },
66 * {
67 * "rgb": {
68 * "b": 135,
69 * "g": 105,
70 * "r": 62
71 * }
72 * },
73 * {
74 * "rgb": {
75 * "b": 195,
76 * "g": 154,
77 * "r": 105
78 * }
79 * },
80 * {
81 * "rgb": {
82 * "b": 230,
83 * "g": 190,
84 * "r": 141
85 * }
86 * },
87 * {
88 * "rgb": {
89 * "b": 96,
90 * "g": 77,
91 * "r": 44
92 * }
93 * },
94 * {
95 * "rgb": {
96 * "b": 144,
97 * "g": 135,
98 * "r": 99
99 * }
100 * },
101 * {
102 * "rgb": {
103 * "b": 64,
104 * "g": 106,
105 * "r": 64
106 * }
107 * },
108 * {
109 * "rgb": {
110 * "b": 178,
111 * "g": 131,
112 * "r": 80
113 * }
114 * },
115 * {
116 * "rgb": {
117 * "b": 247,
118 * "g": 230,
119 * "r": 185
120 * }
121 * },
122 * {
123 * "rgb": {
124 * "b": 75,
125 * "g": 145,
126 * "r": 97
127 * }
128 * }
129 * ],
130 * "prominent": {
131 * "rgb": {
132 * "b": 41,
133 * "g": 41,
134 * "r": 24
135 * }
136 * }
137 * },
138 * "faces": [],
139 * "image": "wix:image://v1/d4dde1_0c8b26126ba94f3daee16d9e9be04f0c~mv2.jpg/river.jpg#originWidth=5760&originHeight=3840"
140 * }
141 * },
142 * "mediaType": "IMAGE",
143 * "operationStatus": "READY",
144 * "parentFolderId": "b2bc72834460412494c93617d88b8c89",
145 * "private": false,
146 * "siteId": "3ecba886-4267-11ee-be56-0242ac120002",
147 * "sizeInBytes": "3677628",
148 * "state": "OK",
149 * "thumbnailUrl": "https://static.wixstatic.com/media/d4dde1_0c8b26126ba94f3daee16d9e9be04f0c~mv2.jpg",
150 * "url": "https://static.wixstatic.com/media/d4dde1_0c8b26126ba94f3daee16d9e9be04f0c~mv2.jpg"
151 * }
152 */
Update a file's location (export from backend code)

Copy Code
1import { Permissions, webMethod } from 'wix-web-module';
2import { files } from 'wix-media.v2';
3import { elevate } from 'wix-auth';
4
5/* Sample id value: 'd4dde1_0c8b26126ba94f3daee16d9e9be04f0c~mv2.jpg'
6 *
7 * Sample file value:
8 * {
9 * parentFolderId: 'b2bc72834460412494c93617d88b8c89'
10 * }
11 */
12
13export const myUpdateFileDescriptorFunction = webMethod(Permissions.Anyone, async (id, file) => {
14 try {
15 const elevatedUpdateFileDescriptor = elevate(files.updateFileDescriptor);
16 const updatedDescriptor = await elevatedUpdateFileDescriptor(id, file);
17
18 console.log("Updated:", updatedDescriptor);
19 return updatedDescriptor;
20 } catch (error) {
21 console.error(error);
22 // Handle the error
23 }
24});
25
26/* Promise resolves to:
27 * {
28 * "_createdDate": "2023-08-09T08:45:50.000Z",
29 * "_id": "d4dde1_0c8b26126ba94f3daee16d9e9be04f0c~mv2.jpg",
30 * "_updatedDate": "2023-09-10T09:53:50.000Z",
31 * "displayName": "river.jpg",
32 * "hash": "2f2a61275002b90e6e8fa1be4674c4a7",
33 * "internalTags": [
34 * "_fileOrigin_uploaded"
35 * ],
36 * "labels": [
37 * "mountain stream",
38 * "clear stream",
39 * "flowing water",
40 * "mountain torrent",
41 * "free-flowing",
42 * "streams",
43 * "running water",
44 * "downstream",
45 * "watercourse",
46 * "stream",
47 * "riverbed",
48 * "freshwater",
49 * "landscape photograph",
50 * "motion blur",
51 * "fresh water",
52 * "river bank",
53 * "torrent",
54 * "flow into",
55 * "landscape photography",
56 * "natural scenery"
57 * ],
58 * "media": {
59 * "image": {
60 * "colors": {
61 * "palette": [
62 * {
63 * "rgb": {
64 * "b": 41,
65 * "g": 41,
66 * "r": 24
67 * }
68 * },
69 * {
70 * "rgb": {
71 * "b": 135,
72 * "g": 105,
73 * "r": 62
74 * }
75 * },
76 * {
77 * "rgb": {
78 * "b": 195,
79 * "g": 154,
80 * "r": 105
81 * }
82 * },
83 * {
84 * "rgb": {
85 * "b": 230,
86 * "g": 190,
87 * "r": 141
88 * }
89 * },
90 * {
91 * "rgb": {
92 * "b": 96,
93 * "g": 77,
94 * "r": 44
95 * }
96 * },
97 * {
98 * "rgb": {
99 * "b": 144,
100 * "g": 135,
101 * "r": 99
102 * }
103 * },
104 * {
105 * "rgb": {
106 * "b": 64,
107 * "g": 106,
108 * "r": 64
109 * }
110 * },
111 * {
112 * "rgb": {
113 * "b": 178,
114 * "g": 131,
115 * "r": 80
116 * }
117 * },
118 * {
119 * "rgb": {
120 * "b": 247,
121 * "g": 230,
122 * "r": 185
123 * }
124 * },
125 * {
126 * "rgb": {
127 * "b": 75,
128 * "g": 145,
129 * "r": 97
130 * }
131 * }
132 * ],
133 * "prominent": {
134 * "rgb": {
135 * "b": 41,
136 * "g": 41,
137 * "r": 24
138 * }
139 * }
140 * },
141 * "faces": [],
142 * "image": "wix:image://v1/d4dde1_0c8b26126ba94f3daee16d9e9be04f0c~mv2.jpg/river.jpg#originWidth=5760&originHeight=3840"
143 * }
144 * },
145 * "mediaType": "IMAGE",
146 * "operationStatus": "READY",
147 * "parentFolderId": "b2bc72834460412494c93617d88b8c89",
148 * "private": false,
149 * "siteId": "3ecba886-4267-11ee-be56-0242ac120002",
150 * "sizeInBytes": "3677628",
151 * "state": "OK",
152 * "thumbnailUrl": "https://static.wixstatic.com/media/d4dde1_0c8b26126ba94f3daee16d9e9be04f0c~mv2.jpg",
153 * "url": "https://static.wixstatic.com/media/d4dde1_0c8b26126ba94f3daee16d9e9be04f0c~mv2.jpg"
154 * }
155 */
156
Update a file's display name and labels

Copy Code
1import { Permissions, webMethod } from 'wix-web-module';
2import { files } from 'wix-media.v2';
3import { elevate } from 'wix-auth';
4
5/* Sample id value: 'd4dde1_0c8b26126ba94f3daee16d9e9be04f0c~mv2.jpg'
6 *
7 * Sample file value:
8 * {
9 * displayName: 'river',
10 * labels: ['water', 'flowing', 'nature']
11 * }
12 */
13
14export const myUpdateFileDescriptorFunction = webMethod(Permissions.Anyone, async (id, file) => {
15 try {
16 const elevatedUpdateFileDescriptor = elevate(files.updateFileDescriptor);
17 const updatedDescriptor = await elevatedUpdateFileDescriptor(id, file);
18
19 console.log("Updated:", updatedDescriptor);
20 return updatedDescriptor;
21 } catch (error) {
22 console.error(error);
23 // Handle the error
24 }
25});
26
27/* Promise resolves to:
28 * {
29 * "_createdDate": "2023-08-09T08:45:50.000Z",
30 * "_id": "d4dde1_0c8b26126ba94f3daee16d9e9be04f0c~mv2.jpg",
31 * "_updatedDate": "2023-08-14T09:48:28.000Z",
32 * "displayName": "river",
33 * "hash": "2f2a61275002b90e6e8fa1be4674c4a7",
34 * "internalTags": [
35 * "_fileOrigin_uploaded"
36 * ],
37 * "labels": [
38 * "water",
39 * "flowing",
40 * "nature"
41 * ],
42 * "media": {
43 * "image": {
44 * "colors": {
45 * "palette": [
46 * {
47 * "rgb": {
48 * "b": 41,
49 * "g": 41,
50 * "r": 24
51 * }
52 * },
53 * {
54 * "rgb": {
55 * "b": 135,
56 * "g": 105,
57 * "r": 62
58 * }
59 * },
60 * {
61 * "rgb": {
62 * "b": 195,
63 * "g": 154,
64 * "r": 105
65 * }
66 * },
67 * {
68 * "rgb": {
69 * "b": 230,
70 * "g": 190,
71 * "r": 141
72 * }
73 * },
74 * {
75 * "rgb": {
76 * "b": 96,
77 * "g": 77,
78 * "r": 44
79 * }
80 * },
81 * {
82 * "rgb": {
83 * "b": 144,
84 * "g": 135,
85 * "r": 99
86 * }
87 * },
88 * {
89 * "rgb": {
90 * "b": 64,
91 * "g": 106,
92 * "r": 64
93 * }
94 * },
95 * {
96 * "rgb": {
97 * "b": 178,
98 * "g": 131,
99 * "r": 80
100 * }
101 * },
102 * {
103 * "rgb": {
104 * "b": 247,
105 * "g": 230,
106 * "r": 185
107 * }
108 * },
109 * {
110 * "rgb": {
111 * "b": 75,
112 * "g": 145,
113 * "r": 97
114 * }
115 * }
116 * ],
117 * "prominent": {
118 * "rgb": {
119 * "b": 41,
120 * "g": 41,
121 * "r": 24
122 * }
123 * }
124 * },
125 * "faces": [],
126 * "image": "wix:image://v1/d4dde1_0c8b26126ba94f3daee16d9e9be04f0c~mv2.jpg/river#originWidth=5760&originHeight=3840"
127 * }
128 * },
129 * "mediaType": "IMAGE",
130 * "operationStatus": "READY",
131 * "parentFolderId": "b2bc72834460412494c93617d88b8c89",
132 * "private": false,
133 * "siteId": "3ecba886-4267-11ee-be56-0242ac120002",
134 * "sizeInBytes": "3677628",
135 * "state": "OK",
136 * "thumbnailUrl": "https://static.wixstatic.com/media/d4dde1_0c8b26126ba94f3daee16d9e9be04f0c~mv2.jpg",
137 * "url": "https://static.wixstatic.com/media/d4dde1_0c8b26126ba94f3daee16d9e9be04f0c~mv2.jpg"
138 * }
139 */
Update a file's display name from visitor input

This code uses the visitor's input on the page to update the display name of an image which they choose from a dropdown list on the page.

Copy Code
1/*************************************
2 * Backend code - update-file.web.js *
3 ************************************/
4
5import { Permissions, webMethod } from 'wix-web-module';
6import { files } from 'wix-media.v2';
7import { elevate } from 'wix-auth';
8
9export const updateFile = webMethod(Permissions.Anyone, async (fileId, file) => {
10 try {
11 const elevatedUpdateFileDescriptor = elevate(files.updateFileDescriptor);
12 const updatedDescriptor = await elevatedUpdateFileDescriptor(fileId, file);
13
14 return updatedDescriptor;
15 } catch (error) {
16 console.error(error);
17 }
18});
19
20export const listImages = webMethod(Permissions.Anyone, async () => {
21 const listOptions = {
22 mediaTypes: ["IMAGE"]
23 }
24
25 try {
26 const elevatedListFiles = elevate(files.listFiles)
27 const images = await elevatedListFiles(listOptions);
28
29 return images.files;
30 } catch (error) {
31 console.error(error);
32 }
33});
34
35
36/*************
37 * Page code *
38 ************/
39
40import { updateFile, listImages } from 'backend/update-file.web';
41
42$w.onReady(async () => {
43 await populateImagesDropdown();
44
45 $w('#update').onClick(async () => {
46 const imageId = $w('#imagesDropdown').value;
47
48 const fileUpdates = {
49 displayName: $w('#newDisplayName').value
50 }
51
52 const updatedLocation = await updateFile(imageId, fileUpdates);
53 console.log('Display name successfully updated to:', updatedLocation.displayName)
54 $w('#updateSuccessMsg').show();
55 });
56});
57
58async function populateImagesDropdown() {
59 const images = await listImages();
60 const dropdownOptions = images.map((image) => {
61 return {
62 label: image.displayName,
63 value: image._id
64 };
65 });
66
67 $w('#imagesDropdown').options = dropdownOptions;
68};