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.
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
File ID. Generated when a file is uploaded to the Media Manager.
Returns
Information about the updated file.
Return Type:
NAME
TYPE
DESCRIPTION
Date and time the file was created.
File ID. Generated when a file is uploaded to the Media Manager.
Date and time the file was updated.
File name as it appears in the Media Manager.
File hash.
Labels assigned to media files that describe and categorize them. Provided by the user, or generated by Google Vision API for images.
Media file content.
Media file type.
Supported values: "IMAGE"
, "VIDEO"
, "AUDIO"
, "DOCUMENT"
, "VECTOR"
, "ARCHIVE"
, "MODEL3D"
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.
ID of the file's parent folder.
Whether the link to the uploaded file is public or private. Private links require a token.
The Wix site ID where the media file is stored.
Size of the uploaded file in bytes.
URL where the file was uploaded from.
State of the file.
Supported values: "OK"
, "DELETED"
URL of the file's thumbnail.
Static URL of the file.
Was this helpful?
1import { files } from 'wix-media.v2';23/* Sample id value: 'd4dde1_0c8b26126ba94f3daee16d9e9be04f0c~mv2.jpg'4 *5 * Sample file value:6 * {7 * parentFolderId: 'b2bc72834460412494c93617d88b8c89'8 * }9 */1011async function myUpdateFileDescriptorFunction(id, file) {12 try {13 const updatedDescriptor = await files.updateFileDescriptor(id, file);1415 console.log("Updated:", updatedDescriptor);16 return updatedDescriptor;17 } catch (error) {18 console.error(error);19 // Handle the error20 }21}2223/* 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": 2464 * }65 * },66 * {67 * "rgb": {68 * "b": 135,69 * "g": 105,70 * "r": 6271 * }72 * },73 * {74 * "rgb": {75 * "b": 195,76 * "g": 154,77 * "r": 10578 * }79 * },80 * {81 * "rgb": {82 * "b": 230,83 * "g": 190,84 * "r": 14185 * }86 * },87 * {88 * "rgb": {89 * "b": 96,90 * "g": 77,91 * "r": 4492 * }93 * },94 * {95 * "rgb": {96 * "b": 144,97 * "g": 135,98 * "r": 9999 * }100 * },101 * {102 * "rgb": {103 * "b": 64,104 * "g": 106,105 * "r": 64106 * }107 * },108 * {109 * "rgb": {110 * "b": 178,111 * "g": 131,112 * "r": 80113 * }114 * },115 * {116 * "rgb": {117 * "b": 247,118 * "g": 230,119 * "r": 185120 * }121 * },122 * {123 * "rgb": {124 * "b": 75,125 * "g": 145,126 * "r": 97127 * }128 * }129 * ],130 * "prominent": {131 * "rgb": {132 * "b": 41,133 * "g": 41,134 * "r": 24135 * }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 */
1import { Permissions, webMethod } from 'wix-web-module';2import { files } from 'wix-media.v2';3import { elevate } from 'wix-auth';45/* Sample id value: 'd4dde1_0c8b26126ba94f3daee16d9e9be04f0c~mv2.jpg'6 *7 * Sample file value:8 * {9 * parentFolderId: 'b2bc72834460412494c93617d88b8c89'10 * }11 */1213export const myUpdateFileDescriptorFunction = webMethod(Permissions.Anyone, async (id, file) => {14 try {15 const elevatedUpdateFileDescriptor = elevate(files.updateFileDescriptor);16 const updatedDescriptor = await elevatedUpdateFileDescriptor(id, file);1718 console.log("Updated:", updatedDescriptor);19 return updatedDescriptor;20 } catch (error) {21 console.error(error);22 // Handle the error23 }24});2526/* 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": 2467 * }68 * },69 * {70 * "rgb": {71 * "b": 135,72 * "g": 105,73 * "r": 6274 * }75 * },76 * {77 * "rgb": {78 * "b": 195,79 * "g": 154,80 * "r": 10581 * }82 * },83 * {84 * "rgb": {85 * "b": 230,86 * "g": 190,87 * "r": 14188 * }89 * },90 * {91 * "rgb": {92 * "b": 96,93 * "g": 77,94 * "r": 4495 * }96 * },97 * {98 * "rgb": {99 * "b": 144,100 * "g": 135,101 * "r": 99102 * }103 * },104 * {105 * "rgb": {106 * "b": 64,107 * "g": 106,108 * "r": 64109 * }110 * },111 * {112 * "rgb": {113 * "b": 178,114 * "g": 131,115 * "r": 80116 * }117 * },118 * {119 * "rgb": {120 * "b": 247,121 * "g": 230,122 * "r": 185123 * }124 * },125 * {126 * "rgb": {127 * "b": 75,128 * "g": 145,129 * "r": 97130 * }131 * }132 * ],133 * "prominent": {134 * "rgb": {135 * "b": 41,136 * "g": 41,137 * "r": 24138 * }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
1import { Permissions, webMethod } from 'wix-web-module';2import { files } from 'wix-media.v2';3import { elevate } from 'wix-auth';45/* Sample id value: 'd4dde1_0c8b26126ba94f3daee16d9e9be04f0c~mv2.jpg'6 *7 * Sample file value:8 * {9 * displayName: 'river',10 * labels: ['water', 'flowing', 'nature']11 * }12 */1314export const myUpdateFileDescriptorFunction = webMethod(Permissions.Anyone, async (id, file) => {15 try {16 const elevatedUpdateFileDescriptor = elevate(files.updateFileDescriptor);17 const updatedDescriptor = await elevatedUpdateFileDescriptor(id, file);1819 console.log("Updated:", updatedDescriptor);20 return updatedDescriptor;21 } catch (error) {22 console.error(error);23 // Handle the error24 }25});2627/* 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": 2451 * }52 * },53 * {54 * "rgb": {55 * "b": 135,56 * "g": 105,57 * "r": 6258 * }59 * },60 * {61 * "rgb": {62 * "b": 195,63 * "g": 154,64 * "r": 10565 * }66 * },67 * {68 * "rgb": {69 * "b": 230,70 * "g": 190,71 * "r": 14172 * }73 * },74 * {75 * "rgb": {76 * "b": 96,77 * "g": 77,78 * "r": 4479 * }80 * },81 * {82 * "rgb": {83 * "b": 144,84 * "g": 135,85 * "r": 9986 * }87 * },88 * {89 * "rgb": {90 * "b": 64,91 * "g": 106,92 * "r": 6493 * }94 * },95 * {96 * "rgb": {97 * "b": 178,98 * "g": 131,99 * "r": 80100 * }101 * },102 * {103 * "rgb": {104 * "b": 247,105 * "g": 230,106 * "r": 185107 * }108 * },109 * {110 * "rgb": {111 * "b": 75,112 * "g": 145,113 * "r": 97114 * }115 * }116 * ],117 * "prominent": {118 * "rgb": {119 * "b": 41,120 * "g": 41,121 * "r": 24122 * }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 */
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.
1/*************************************2 * Backend code - update-file.web.js *3 ************************************/45import { Permissions, webMethod } from 'wix-web-module';6import { files } from 'wix-media.v2';7import { elevate } from 'wix-auth';89export const updateFile = webMethod(Permissions.Anyone, async (fileId, file) => {10 try {11 const elevatedUpdateFileDescriptor = elevate(files.updateFileDescriptor);12 const updatedDescriptor = await elevatedUpdateFileDescriptor(fileId, file);1314 return updatedDescriptor;15 } catch (error) {16 console.error(error);17 }18});1920export const listImages = webMethod(Permissions.Anyone, async () => {21 const listOptions = {22 mediaTypes: ["IMAGE"]23 }2425 try {26 const elevatedListFiles = elevate(files.listFiles)27 const images = await elevatedListFiles(listOptions);2829 return images.files;30 } catch (error) {31 console.error(error);32 }33});343536/*************37 * Page code *38 ************/3940import { updateFile, listImages } from 'backend/update-file.web';4142$w.onReady(async () => {43 await populateImagesDropdown();4445 $w('#update').onClick(async () => {46 const imageId = $w('#imagesDropdown').value;4748 const fileUpdates = {49 displayName: $w('#newDisplayName').value50 }5152 const updatedLocation = await updateFile(imageId, fileUpdates);53 console.log('Display name successfully updated to:', updatedLocation.displayName)54 $w('#updateSuccessMsg').show();55 });56});5758async function populateImagesDropdown() {59 const images = await listImages();60 const dropdownOptions = images.map((image) => {61 return {62 label: image.displayName,63 value: image._id64 };65 });6667 $w('#imagesDropdown').options = dropdownOptions;68};