Type parameters

Hierarchy

Properties

Readonly code

code: string

App code of the URL’s target (the app’s code).

Readonly id

id: string

ID of the URL’s target.

Readonly namespace

namespace: string

Namespace of the URL target (the code of the workspace that the app belongs to).

Methods

fetch

getDownloadUrl

  • The method returns a link to download a file’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 is attachment .

    const url = await file.getDownloadUrl();
    

    Parameters

    Returns Promise<string>

getPermissions

  • The method receives a file’s permissions.

    After a successful permissions request, you will get a TPermissions object. This object can be modified or analyzed for various permission checks.

    const perm = await file.getPermissions();
    

    Returns Promise<TPermissions>

getStaticDownloadUrl

  • The method returns a permanent link to download a file’s content.

    The returned link contains a redirect to the link with the file’s content. This link can be used only by authorized users who have sufficient permissions to download the file. The attachment type can be attachment orinline. By default, the dispositionType parameter is set to attachment. The link is permanent. It exists until the file is deleted in the system.

    // Get the file’s ID 
    const fileUUID = Context. data.fileID; 
    if(!fileUUID) { 
     return; 
    } 
    // Search for the file 
    const  file = await System.files.search().where(x => x.__id.eq(fileUUID)).first();  
    if(!file) { 
     return; 
    } 
    // Get a permanent link to the file 
    const url =  file.getStaticDownloadUrl(); 
    

    Parameters

    Returns string

hasPermission

  • hasPermission(group: TPermissionOrgunit, type: PermissionType): Promise<boolean>
  • The method checks access permissions PermissionType.

    The method allows you to easily check whether it is possible to perform a PermissionType operation with a file. The method returns a flag. If its value is true, the user can perform the requested operation with the file. It is also possible to check access permissions for an org chart item.

    const user = Context.data.__createdBy;
    const canUpdate = await  file.hasPermission(user, PermissionType.UPDATE); 
    

    Parameters

    • group: TPermissionOrgunit

      The group or user whose permissions are checked.

    • type: PermissionType

      Operation type.

    Returns Promise<boolean>

setPermissions

  • The method sets access permissions for a file.

    This method is used when you need to change a file’s access settings by adding or deleting access permissions for a user, a group, or an org chart item. To add new access permissions, use the TPermissionValue object. To grant access to specific operations, use PermissionType. When a new TPermissions object is created, use the FileItem.setPermissions method to save the new access permissions.

    const user =  Context.data.__createdBy;
    const permissions = new Permissions([ 
     new  PermissionValue(user, [PermissionType.DELETE, PermissionType.READ]), 
    ]);  
    await file.setPermissions(perms); 
    

    Parameters

    Returns Promise<void>