Type parameters
Hierarchy
- BaseItem<FileVersionData>
-
ItemRef<FileVersionItem>
- FileVersionItem
Properties
Readonly code
App code of the URL’s target (the app’s code).
Readonly data
Values of object’s fields.
Readonly fields
Description of the object’s fields.
Readonly id
ID of the URL’s target.
Readonly namespace
Namespace of the URL target (the code of the workspace that the app belongs to).
Methods
delete
-
The method deletes a file’s version.
When a version is deleted, its number is decremented by one. The numbers of all versions after the deleted one are also decremented by one to keep the order of versions accurate.
// Extract a file from the context to work with its versions const file = Context.data.file; const fileVersions = file.getVersions(0, 1); if (fileVersions.length === 0) { throw new Error('The file has no versions'); } // Delete the latest file version await fileVersions[0].delete();
Returns Promise<void>
fetch
-
Request complete data of a reference object.
Returns Promise<FileVersionItem>
getDownloadUrl
-
The method returns a link to download a file version’s content.
The URL can be used to get the file’s content. Using this link, even anonymous users can download the file. The download link is active for one hour. You can set how the file will be displayed, as an attachment or inline. The default value of the
dispositionType
parameter isattachment
.const url = await version.getDownloadUrl();
Parameters
-
Optional dispositionType: DispositionType
Type of attachment.
Returns Promise<string>
-
normalize
-
Delete duplicate data in arrays.
The method deletes duplicates in fields that store arrays of links to system objects (users, files, app items, or documents). For example, you can call this method after bulk editing a lot of data within an object.
const app1 = await Context.data.app1.fetch(); const app2 = await Context.data.app2.fetch(); app1.data.executors.push(app2.data. executors); app1.normalize(); // Now we need to go over the elements in the new array app1.data.executors.forEach( ... );
Returns void
setAsCurrent
-
The method saves a version as current.
The chosen version object is set as the current version of the file. You can create a copy of the version and make it current. To do that, set the
copy
flag totrue
. You can also call the method without arguments. Then the order of versions will change, and the selected version will be made the latest and the current version of the file. In the example, a file stored in the context is restored so that its first version becomes current. This cancels all changes made to it.// Extract a file from the context to work with its versions const file = Context.data.file; const firstVersions = await file.getVersions(0, 2); if (firstVersions.length < 2) { throw new Error('No versions to be restored'); } // Set the first version as current to restore the original content of the file const updatedFile = await firstVersions[1].setAsCurrent(true);
Parameters
-
Optional copy: undefined | false | true
Flag showing whether the version should be copied.
-
Optional comment: undefined | string
Comment for setting the version as current.
Returns Promise<FileItem>
-
File version
The object is used to work with file versions. It allows downloading archived file versions and get links to download them. You can get all versions of a file using the FileItem.getVersions method.