# Class File

File Descriptor class

Architecture tips:

1. Physically Saltcorn stores files on local filesystem of the server, where Saltcorn runs.
2. The path to file store is defined in db.connectObj.file_store.
3. List of files stored in _sc_files table in Saltcorn database.
4. Each tenant has own file list and file storage.
5. This class provides file descriptor and basic functions to manipulate with files.

#### Hierarchy

- File

- Defined in saltcorn-data/models/file.ts:55
- Defined in saltcorn-data/models/file.ts:757

#####
Index

### Constructors

constructor

### Properties

filename
id?
isDirectory
location
mime_sub
mime_super
min_role_read
s3_store
size_kb
uploaded_at
user_id?

### Accessors

absolutePath
current_folder
mimetype
path_to_serve

### Methods

delete
get_contents
is_symlink
move_to_dir
overwrite_contents
rename
set_role
set_user
absPathToServePath
allDirectories
buildDirCache
create
destroyDirCache
ensure_file_store
find
findOne
from_contents
from_file_on_disk
from_req_files
getDirCache
get_new_path
nameToMimeType
new_folder
normalise
normalise_in_base
rootFolder
set_xattr_of_existing_file
update
update_table_references
upload

## Constructors

### constructor

- new File(o): File

- Constructor

  #### Parameters

  - ##### o: FileCfg

    {object}

  #### Returns File

  - Defined in saltcorn-data/models/file.ts:72

## Properties

### filename

filename: string

- Defined in saltcorn-data/models/file.ts:56

### `Optional` id

id?: number

- Defined in saltcorn-data/models/file.ts:62

### isDirectory

isDirectory: boolean

- Defined in saltcorn-data/models/file.ts:66

### location

location: string

- Defined in saltcorn-data/models/file.ts:57

### mime_sub

mime_sub: string

- Defined in saltcorn-data/models/file.ts:59

### mime_super

mime_super: string

- Defined in saltcorn-data/models/file.ts:58

### min_role_read

min_role_read: number

- Defined in saltcorn-data/models/file.ts:64

### s3_store

s3_store: boolean

- Defined in saltcorn-data/models/file.ts:65

### size_kb

size_kb: number

- Defined in saltcorn-data/models/file.ts:61

### uploaded_at

uploaded_at: Date

- Defined in saltcorn-data/models/file.ts:60

### `Optional` user_id

user_id?: number

- Defined in saltcorn-data/models/file.ts:63

## Accessors

### absolutePath

- get absolutePath(): string

- #### Returns string

  - Defined in saltcorn-data/models/file.ts:192

### current_folder

- get current_folder(): string

- Get current folder

  #### Returns string

  - Defined in saltcorn-data/models/file.ts:390

### mimetype

- get mimetype(): string

- MIME type of the file

  #### Returns string

  - Defined in saltcorn-data/models/file.ts:698

### path_to_serve

- get path_to_serve(): string | number

- Get path to serve

  #### Returns string | number

  - Defined in saltcorn-data/models/file.ts:377

## Methods

### delete

- delete(unlinker?): Promise<void | {
  error: string;
  }>

- Delete file

  #### Parameters

  - ##### `Optional` unlinker: ((arg0) => Promise<void>)

    - - (arg0): Promise<void>

      - #### Parameters

        - ##### arg0: File

        #### Returns Promise<void>

  #### Returns Promise<void | {
  error: string;
  }>

  - Defined in saltcorn-data/models/file.ts:666

### get_contents

- get_contents(encoding?): Promise<Buffer>

- #### Parameters

  - ##### `Optional` encoding: "utf8" | "base64" | "base64url" | "hex" | "ascii"

  #### Returns Promise<Buffer>

  - Defined in saltcorn-data/models/file.ts:609

### is_symlink

- is_symlink(): Promise<boolean>

- #### Returns Promise<boolean>

  - Defined in saltcorn-data/models/file.ts:240

### move_to_dir

- move_to_dir(newFolder): Promise<void>

- Move file to other folder

  #### Parameters

  - ##### newFolder: string

    target folder for file

  #### Returns Promise<void>

  - Defined in saltcorn-data/models/file.ts:480

### overwrite_contents

- overwrite_contents(contents): Promise<void>

- #### Parameters

  - ##### contents: string | Buffer | ArrayBuffer

  #### Returns Promise<void>

  - Defined in saltcorn-data/models/file.ts:655

### rename

- rename(filenameIn): Promise<void>

- Rename file

  #### Parameters

  - ##### filenameIn: string

    target file name

  #### Returns Promise<void>

  - Defined in saltcorn-data/models/file.ts:438

### set_role

- set_role(min_role_read): Promise<void>

- Set Min Role to read for file

  #### Parameters

  - ##### min_role_read: number

    target Role for file to read

  #### Returns Promise<void>

  - Defined in saltcorn-data/models/file.ts:408

### set_user

- set_user(user_id): Promise<void>

- Set user for file

  #### Parameters

  - ##### user_id: number

    target user_id

  #### Returns Promise<void>

  - Defined in saltcorn-data/models/file.ts:425

### `Static` absPathToServePath

- absPathToServePath(absPath): string

- #### Parameters

  - ##### absPath: string | number

  #### Returns string

  - Defined in saltcorn-data/models/file.ts:185

### `Static` allDirectories

- allDirectories(ignoreCache?): Promise<File[]>

- get all directories in the root folder (tenant root dir for multi-tenant)

  #### Parameters

  - ##### `Optional` ignoreCache: boolean

    if a cache exists, ignore it

  #### Returns Promise<File[]>

  - Defined in saltcorn-data/models/file.ts:203

### `Static` buildDirCache

- buildDirCache(): Promise<void>

- #### Returns Promise<void>

  - Defined in saltcorn-data/models/file.ts:228

### `Static` create

- create(f): Promise<File>

- Create file

  #### Parameters

  - ##### f: FileCfg

  #### Returns Promise<File>

  - Defined in saltcorn-data/models/file.ts:709

### `Static` destroyDirCache

- destroyDirCache(): void

- #### Returns void

  - Defined in saltcorn-data/models/file.ts:236

### `Static` ensure_file_store

- ensure_file_store(tenant_name?): Promise<void>

- Ensure that file_store path is physically exists in file system. In reality just recursively creates full absolute path to db.connectObj.file_store.

  #### Parameters

  - ##### `Optional` tenant_name: string

  #### Returns Promise<void>

  - Defined in saltcorn-data/models/file.ts:547

### `Static` find

- find(where?, selectopts?): Promise<File[]>

- Select list of file descriptors

  #### Parameters

  - ##### `Optional` where: Where

  - ##### selectopts: SelectOptions = {}

  #### Returns Promise<File[]>

  - Defined in saltcorn-data/models/file.ts:96

### `Static` findOne

- findOne(where): Promise<null | File>

- Select one file descriptor

  #### Parameters

  - ##### where: string | Where

  #### Returns Promise<null | File>

  - Defined in saltcorn-data/models/file.ts:307

### `Static` from_contents

- from_contents(name, mimetype, contents, user_id, min_role_read?, folder?): Promise<File>

- Create new file

  #### Parameters

  - ##### name: string

  - ##### mimetype: string

  - ##### contents: string | Buffer | ArrayBuffer

  - ##### user_id: number

  - ##### min_role_read: number = 1

  - ##### folder: string = "/"

  #### Returns Promise<File>

  - Defined in saltcorn-data/models/file.ts:624

### `Static` from_file_on_disk

- from_file_on_disk(name, absoluteFolder): Promise<File>

- #### Parameters

  - ##### name: string

  - ##### absoluteFolder: string

  #### Returns Promise<File>

  - Defined in saltcorn-data/models/file.ts:255

### `Static` from_req_files

- from_req_files(file, user_id, min_role_read?, folder?): Promise<File>

- Create new file

  #### Parameters

  - ##### file: {
    mimetype: string;
    mv: Function;
    name: string;
    s3object?: boolean;
    size: number;
    }

    - ##### mimetype: string

    - ##### mv: Function

    - ##### name: string

    - ##### `Optional` s3object?: boolean

    - ##### size: number

  - ##### user_id: number

  - ##### min_role_read: number = 1

  - ##### folder: string = "/"

  #### Returns Promise<File>

  - Defined in saltcorn-data/models/file.ts:571

### `Static` getDirCache

- getDirCache(): null | File[]

- #### Returns null | File[]

  - Defined in saltcorn-data/models/file.ts:232

### `Static` get_new_path

- get_new_path(suggest?, renameIfExisting?): string

- Get absolute path to new file in db.connectObj.file_store.

  #### Parameters

  - ##### `Optional` suggest: string

    path to file inside file store. If undefined that autogenerated uudv4 is used.

  - ##### `Optional` renameIfExisting: boolean

  #### Returns string

  - path to file
  - Defined in saltcorn-data/models/file.ts:506

### `Static` nameToMimeType

- nameToMimeType(filepath): string | false

- #### Parameters

  - ##### filepath: string

  #### Returns string | false

  - Defined in saltcorn-data/models/file.ts:249

### `Static` new_folder

- new_folder(name, inFolder?): Promise<void>

- Create new folder

  #### Parameters

  - ##### name: string

  - ##### inFolder: string = ""

  #### Returns Promise<void>

  - Defined in saltcorn-data/models/file.ts:358

### `Static` normalise

- normalise(fpath): string

- #### Parameters

  - ##### fpath: string

  #### Returns string

  - Defined in saltcorn-data/models/file.ts:159

### `Static` normalise_in_base

- normalise_in_base(trusted_base, ...unsafe_paths): null | string

- #### Parameters

  - ##### trusted_base: string

  - ##### `Rest` ...unsafe_paths: string[]

  #### Returns null | string

  - Defined in saltcorn-data/models/file.ts:163

### `Static` rootFolder

- rootFolder(): Promise<File>

- #### Returns Promise<File>

  - Defined in saltcorn-data/models/file.ts:177

### `Static` set_xattr_of_existing_file

- set_xattr_of_existing_file(name, absoluteFolder, user): Promise<void>

- #### Parameters

  - ##### name: string

  - ##### absoluteFolder: string

  - ##### user: User

  #### Returns Promise<void>

  - Defined in saltcorn-data/models/file.ts:744

### `Static` update

- update(id, row): Promise<void>

- Update File descriptor

  #### Parameters

  - ##### id: number

    primary key

  - ##### row: Row

    row data

  #### Returns Promise<void>

  no returns

  - Defined in saltcorn-data/models/file.ts:400

### `Static` update_table_references

- update_table_references(from, to): Promise<void>

- #### Parameters

  - ##### from: string

  - ##### to: string

  #### Returns Promise<void>

  - Defined in saltcorn-data/models/file.ts:460

### `Static` upload

- upload(file): Promise<any>

- This is a mobile-app function, it uploads a file to the saltcorn server.

  #### Parameters

  - ##### file: {
    blob: Blob;
    fileObj: any;
    }

    file to upload

    - ##### blob: Blob

    - ##### fileObj: any

  #### Returns Promise<any>

  JSON response from POST 'file/upload'

  - Defined in saltcorn-data/models/file.ts:725

Generated using TypeDoc