Search.../

updateFileDescriptor( )

Developer Preview

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

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

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