> Portal Navigation: > > - Append `.md` to any URL under `https://dev.wix.com/docs/` to get its markdown version. > - Pages are either content pages (article or reference text) or menu pages (a list of links to child pages). > - To get a menu page, truncate any URL to a parent path and append `.md` (e.g. `https://dev.wix.com/docs/sdk.md`, `https://dev.wix.com/docs/sdk/core-modules.md`). > - Top-level index of all portals: https://dev.wix.com/docs/llms.txt > - Full concatenated docs: https://dev.wix.com/docs/llms-full.txt # Method name: updateFileDescriptor(file: FileDescriptor, options: UpdateFileDescriptorOptions) # Method package: wixMediaV2 # Method menu location: wixMediaV2 --> files --> updateFileDescriptor # Method Link: https://dev.wix.com/docs/velo/apis/wix-media-v2/files/update-file-descriptor.md # Method Description: Updates a file.
Specify the `parentFolderId` parameter to move a file from its current folder to a different folder. # Method Code Examples: *** Note: do not assume any prop names or enum values other than the ones in the example. ## Update a file's location (dashboard page code) ```javascript import { files } from 'wix-media.v2'; /* Sample file value: * { ​ ​ * _id: 'd4dde1_0c8b26126ba94f3daee16d9e9be04f0c~mv2.jpg', * parentFolderId: 'b2bc72834460412494c93617d88b8c89' * } */ async function myUpdateFileDescriptorFunction(file) { try { const updatedDescriptor = await files.updateFileDescriptor(file); console.log("Updated:", updatedDescriptor); return updatedDescriptor; } catch (error) { console.error(error); // Handle the error } } /* Promise resolves to: * { * "_createdDate": "2023-08-09T08:45:50.000Z", * "_id": "d4dde1_0c8b26126ba94f3daee16d9e9be04f0c~mv2.jpg", * "_updatedDate": "2023-09-10T09:53:50.000Z", * "displayName": "river.jpg", * "hash": "2f2a61275002b90e6e8fa1be4674c4a7", * "internalTags": [ * "_fileOrigin_uploaded" * ], * "labels": [ * "mountain stream", * "clear stream", * "flowing water", * "mountain torrent", * "free-flowing", * "streams", * "running water", * "downstream", * "watercourse", * "stream", * "riverbed", * "freshwater", * "landscape photograph", * "motion blur", * "fresh water", * "river bank", * "torrent", * "flow into", * "landscape photography", * "natural scenery" * ], * "media": { * "image": { * "colors": { * "palette": [ * { * "rgb": { * "b": 41, * "g": 41, * "r": 24 * } * }, * { * "rgb": { * "b": 135, * "g": 105, * "r": 62 * } * }, * { * "rgb": { * "b": 195, * "g": 154, * "r": 105 * } * }, * { * "rgb": { * "b": 230, * "g": 190, * "r": 141 * } * }, * { * "rgb": { * "b": 96, * "g": 77, * "r": 44 * } * }, * { * "rgb": { * "b": 144, * "g": 135, * "r": 99 * } * }, * { * "rgb": { * "b": 64, * "g": 106, * "r": 64 * } * }, * { * "rgb": { * "b": 178, * "g": 131, * "r": 80 * } * }, * { * "rgb": { * "b": 247, * "g": 230, * "r": 185 * } * }, * { * "rgb": { * "b": 75, * "g": 145, * "r": 97 * } * } * ], * "prominent": { * "rgb": { * "b": 41, * "g": 41, * "r": 24 * } * } * }, * "faces": [], * "image": "wix:image://v1/d4dde1_0c8b26126ba94f3daee16d9e9be04f0c~mv2.jpg/river.jpg#originWidth=5760&originHeight=3840" * } * }, * "mediaType": "IMAGE", * "operationStatus": "READY", * "parentFolderId": "b2bc72834460412494c93617d88b8c89", * "private": false, * "siteId": "3ecba886-4267-11ee-be56-0242ac120002", * "sizeInBytes": "3677628", * "state": "OK", * "thumbnailUrl": "https://static.wixstatic.com/media/d4dde1_0c8b26126ba94f3daee16d9e9be04f0c~mv2.jpg", * "url": "https://static.wixstatic.com/media/d4dde1_0c8b26126ba94f3daee16d9e9be04f0c~mv2.jpg" * } */ ``` ## Update a file's location (export from backend code) ```javascript import { Permissions, webMethod } from 'wix-web-module'; import { files } from 'wix-media.v2'; import { elevate } from 'wix-auth'; /* Sample file value: * { * _id: 'd4dde1_0c8b26126ba94f3daee16d9e9be04f0c~mv2.jpg', * parentFolderId: 'b2bc72834460412494c93617d88b8c89' * } */ export const myUpdateFileDescriptorFunction = webMethod(Permissions.Anyone, async (file) => { try { const elevatedUpdateFileDescriptor = elevate(files.updateFileDescriptor); const updatedDescriptor = await elevatedUpdateFileDescriptor(file); console.log("Updated:", updatedDescriptor); return updatedDescriptor; } catch (error) { console.error(error); // Handle the error } }); /* Promise resolves to: * { * "_createdDate": "2023-08-09T08:45:50.000Z", * "_id": "d4dde1_0c8b26126ba94f3daee16d9e9be04f0c~mv2.jpg", * "_updatedDate": "2023-09-10T09:53:50.000Z", * "displayName": "river.jpg", * "hash": "2f2a61275002b90e6e8fa1be4674c4a7", * "internalTags": [ * "_fileOrigin_uploaded" * ], * "labels": [ * "mountain stream", * "clear stream", * "flowing water", * "mountain torrent", * "free-flowing", * "streams", * "running water", * "downstream", * "watercourse", * "stream", * "riverbed", * "freshwater", * "landscape photograph", * "motion blur", * "fresh water", * "river bank", * "torrent", * "flow into", * "landscape photography", * "natural scenery" * ], * "media": { * "image": { * "colors": { * "palette": [ * { * "rgb": { * "b": 41, * "g": 41, * "r": 24 * } * }, * { * "rgb": { * "b": 135, * "g": 105, * "r": 62 * } * }, * { * "rgb": { * "b": 195, * "g": 154, * "r": 105 * } * }, * { * "rgb": { * "b": 230, * "g": 190, * "r": 141 * } * }, * { * "rgb": { * "b": 96, * "g": 77, * "r": 44 * } * }, * { * "rgb": { * "b": 144, * "g": 135, * "r": 99 * } * }, * { * "rgb": { * "b": 64, * "g": 106, * "r": 64 * } * }, * { * "rgb": { * "b": 178, * "g": 131, * "r": 80 * } * }, * { * "rgb": { * "b": 247, * "g": 230, * "r": 185 * } * }, * { * "rgb": { * "b": 75, * "g": 145, * "r": 97 * } * } * ], * "prominent": { * "rgb": { * "b": 41, * "g": 41, * "r": 24 * } * } * }, * "faces": [], * "image": "wix:image://v1/d4dde1_0c8b26126ba94f3daee16d9e9be04f0c~mv2.jpg/river.jpg#originWidth=5760&originHeight=3840" * } * }, * "mediaType": "IMAGE", * "operationStatus": "READY", * "parentFolderId": "b2bc72834460412494c93617d88b8c89", * "private": false, * "siteId": "3ecba886-4267-11ee-be56-0242ac120002", * "sizeInBytes": "3677628", * "state": "OK", * "thumbnailUrl": "https://static.wixstatic.com/media/d4dde1_0c8b26126ba94f3daee16d9e9be04f0c~mv2.jpg", * "url": "https://static.wixstatic.com/media/d4dde1_0c8b26126ba94f3daee16d9e9be04f0c~mv2.jpg" * } */ ``` ## Update a file's display name and labels ```javascript import { Permissions, webMethod } from 'wix-web-module'; import { files } from 'wix-media.v2'; import { elevate } from 'wix-auth'; /* Sample file value: * { * _id: 'd4dde1_0c8b26126ba94f3daee16d9e9be04f0c~mv2.jpg', * displayName: 'river', * labels: ['water', 'flowing', 'nature'] * } */ export const myUpdateFileDescriptorFunction = webMethod(Permissions.Anyone, async (file) => { try { const elevatedUpdateFileDescriptor = elevate(files.updateFileDescriptor); const updatedDescriptor = await elevatedUpdateFileDescriptor(file); console.log("Updated:", updatedDescriptor); return updatedDescriptor; } catch (error) { console.error(error); // Handle the error } }); /* Promise resolves to: * { * "_createdDate": "2023-08-09T08:45:50.000Z", * "_id": "d4dde1_0c8b26126ba94f3daee16d9e9be04f0c~mv2.jpg", * "_updatedDate": "2023-08-14T09:48:28.000Z", * "displayName": "river", * "hash": "2f2a61275002b90e6e8fa1be4674c4a7", * "internalTags": [ * "_fileOrigin_uploaded" * ], * "labels": [ * "water", * "flowing", * "nature" * ], * "media": { * "image": { * "colors": { * "palette": [ * { * "rgb": { * "b": 41, * "g": 41, * "r": 24 * } * }, * { * "rgb": { * "b": 135, * "g": 105, * "r": 62 * } * }, * { * "rgb": { * "b": 195, * "g": 154, * "r": 105 * } * }, * { * "rgb": { * "b": 230, * "g": 190, * "r": 141 * } * }, * { * "rgb": { * "b": 96, * "g": 77, * "r": 44 * } * }, * { * "rgb": { * "b": 144, * "g": 135, * "r": 99 * } * }, * { * "rgb": { * "b": 64, * "g": 106, * "r": 64 * } * }, * { * "rgb": { * "b": 178, * "g": 131, * "r": 80 * } * }, * { * "rgb": { * "b": 247, * "g": 230, * "r": 185 * } * }, * { * "rgb": { * "b": 75, * "g": 145, * "r": 97 * } * } * ], * "prominent": { * "rgb": { * "b": 41, * "g": 41, * "r": 24 * } * } * }, * "faces": [], * "image": "wix:image://v1/d4dde1_0c8b26126ba94f3daee16d9e9be04f0c~mv2.jpg/river#originWidth=5760&originHeight=3840" * } * }, * "mediaType": "IMAGE", * "operationStatus": "READY", * "parentFolderId": "b2bc72834460412494c93617d88b8c89", * "private": false, * "siteId": "3ecba886-4267-11ee-be56-0242ac120002", * "sizeInBytes": "3677628", * "state": "OK", * "thumbnailUrl": "https://static.wixstatic.com/media/d4dde1_0c8b26126ba94f3daee16d9e9be04f0c~mv2.jpg", * "url": "https://static.wixstatic.com/media/d4dde1_0c8b26126ba94f3daee16d9e9be04f0c~mv2.jpg" * } */ ``` ## Update a file's display name from visitor input ```javascript /************************************* * Backend code - update-file.web.js * ************************************/ import { Permissions, webMethod } from 'wix-web-module'; import { files } from 'wix-media.v2'; import { elevate } from 'wix-auth'; export const updateFile = webMethod(Permissions.Anyone, async (fileId, file) => { try { const elevatedUpdateFileDescriptor = elevate(files.updateFileDescriptor); const updatedDescriptor = await elevatedUpdateFileDescriptor({ _id: fileId, ...file }); return updatedDescriptor; } catch (error) { console.error(error); } }); export const listImages = webMethod(Permissions.Anyone, async () => { const listOptions = { mediaTypes: ["IMAGE"] } try { const elevatedListFiles = elevate(files.listFiles) const images = await elevatedListFiles(listOptions); return images.files; } catch (error) { console.error(error); } }); /************* * Page code * ************/ import { updateFile, listImages } from 'backend/update-file.web'; $w.onReady(async () => { await populateImagesDropdown(); $w('#update').onClick(async () => { const imageId = $w('#imagesDropdown').value; const fileUpdates = { displayName: $w('#newDisplayName').value } const updatedLocation = await updateFile(imageId, fileUpdates); console.log('Display name successfully updated to:', updatedLocation.displayName) $w('#updateSuccessMsg').show(); }); }); async function populateImagesDropdown() { const images = await listImages(); const dropdownOptions = images.map((image) => { return { label: image.displayName, value: image._id }; }); $w('#imagesDropdown').options = dropdownOptions; }; ``` ---