Class File

Creates a file object, which represents one specific file reference. This File object can afterwards be used to up- and download the file contents or to retrieves and change the files metadata.

The file data can be uploaded and downloaded as:

type JavaScript type Description
'arraybuffer' ArrayBuffer The content is represented as a fixed-length raw binary data buffer
'blob' Blob The content is represented as a simple blob
'json' object|array|string The file content is represented as json
'text' string The file content is represented through the string
'base64' string The file content as base64 encoded string
'data-url' string A data url which represents the file content

Hierarchy

  • File

Constructors

  • Creates a new file object which represents a file at the given id. Data which is provided to the constructor will be uploaded by invoking ()

    Parameters

    • fileOptions: FileOptions

      The fileOptions used to create a new file object, or just the id of the file

    Returns File

Properties

[DATA]: null | FileData = null
[ID]: string
[METADATA]: null | FileMetadata = null
db: EntityManager = ...

The database connection to use

isFolder: boolean

Specifies whether this file is a folder.

Accessors

  • get acl(): undefined | Acl
  • The current file acl, only accessible after fetching the metadata or downloading/uploading/providing the file

    Returns undefined | Acl

  • get bucket(): string
  • The root bucket of this file

    Returns string

  • get createdAt(): undefined | Date
  • The creation date of the file, only accessible after fetching the metadata or downloading/uploading/providing the eTag

    Returns undefined | Date

  • get eTag(): undefined | string
  • The eTag of the file, only accessible after fetching the metadata or downloading/uploading/providing the file

    Returns undefined | string

  • get headers(): {
        [name: string]: string;
    }
  • The custom headers of the file, only accessible after fetching the metadata or downloading/uploading/providing the file

    Returns {
        [name: string]: string;
    }

    • [name: string]: string
  • get id(): string
  • The complete id of the file, including folder and name

    Returns string

  • get isMetadataLoaded(): boolean
  • Indicates if the metadata are loaded.

    Returns boolean

  • get key(): string
  • The full path under the bucket of this file

    Returns string

  • get lastModified(): undefined | Date
  • The last modified date of the file, only accessible after fetching the metadata or downloading/uploading/providing the eTag

    Returns undefined | Date

  • get mimeType(): undefined | string
  • The mimeType of the file, only accessible after fetching the metadata or downloading/uploading/providing the file

    Returns undefined | string

  • get name(): string
  • The name of the file

    Returns string

  • get parent(): string
  • The parent folder of the file.

    Returns string

  • get path(): string
  • The full path of the file.

    Returns string

  • get size(): undefined | number
  • The size of the file, only accessible after fetching the metadata or downloading/uploading/providing the file

    Returns undefined | number

  • get url(): string
  • Returns string

Methods

  • Checks whenever metadata are already loaded of the file, throws an error otherwise

    Returns

    Returns void

  • Makes the given message a conditional request based on the file metadata

    Parameters

    • msg: Message

      The message to make conditional

    • options: {
          force?: boolean;
      }

      additional request options

      • Optional force?: boolean

    Returns void

  • The fully url to the file, can be directly used to link the file, i.e. in link tags ot image sources

    Returns

    A url with an optional token, to give direct access o the linked resource

    Parameters

    • Optional authorize: boolean

      Authorize the the link with an temporary token, to give authorized access to this protected resource default false if the root bucket is www, true otherwise

    Returns Promise<string>

  • Deletes a file

    Returns

    A promise which will be fulfilled with this file object, or with a list of all deleted files, if this file is an folder

    Parameters

    • Optional deleteOptions: {
          force?: boolean;
      }

      The delete options

      • Optional force?: boolean
    • Optional doneCallback: any

      The callback is invoked after the deletion succeed successfully

    • Optional failCallback: any

      The callback is invoked if any error is occurred

    Returns Promise<File | File[]>

  • Download a file and providing it in the requested type

    Returns

    A promise which will be fulfilled with the downloaded file content

    Parameters

    • Optional downloadOptions: {
          refresh?: false;
          type?: ResponseBodyType;
      }

      The download options

    • Optional doneCallback: any

      The callback is invoked after the download succeed successfully

    • Optional failCallback: any

      The callback is invoked if any error is occurred

    Returns Promise<ArrayBuffer | Blob | ReadStream | Json | File>

  • Parameters

    • headers: {
          [header: string]: string;
      }
      • [header: string]: string

    Returns void

  • Deserialize the given JSON file metadata back to this file instance

    If the JSON object contains an ID, it must match with this file ID, otherwise an exception is thrown.

    Parameters

    Returns void

  • Private

    Gets the MIME type of given file options.

    Returns

    Returns the guessed MIME type or null, if it could not be guessed.

    Parameters

    Returns null | string

  • Gets the file metadata of a file

    Returns

    A promise which will be fulfilled with this file

    Parameters

    • Optional options: {
          refresh?: boolean;
      }

      The load metadata options

      • Optional refresh?: boolean

        Force a revalidation while fetching the metadata

    • Optional doneCallback: any

      The callback is invoked after the metadata is fetched

    • Optional failCallback: any

      The callback is invoked if any error has occurred

    Returns Promise<File>

  • Updates the mata data of this file.

    Returns

    A promise which will be fulfilled with this file

    Parameters

    • Optional options: {
          force?: boolean;
      }

      The save metadata options

      • Optional force?: boolean

        force the update and overwrite the existing metadata without validating it

    • Optional doneCallback: any

      The callback is invoked after the metadata is saved

    • Optional failCallback: any

      The callback is invoked if any error has occurred

    Returns Promise<File>

  • Private

    Validates and sets the file metadata based on the given options

    Parameters

    Returns void

  • Serialize the file metadata of this object to json

    Returns

    The serialized file metadata as json

    Returns JsonMap

  • Uploads the file content which was provided in the constructor or by uploadOptions.data

    Returns

    A promise which will be fulfilled with this file object where the metadata is updated

    Parameters

    • Optional uploadOptions: FileData & FileMetadata & {
          force?: boolean;
          progress?: ProgressListener;
      }

      The upload options

    • Optional doneCallback: any

      The callback is invoked after the upload succeed successfully

    • Optional failCallback: any

      The callback is invoked if any error is occurred

    Returns Promise<File>

  • Parses an E-Tag header

    Returns

    Returns the parsed E-Tag or null, if it could not be parsed

    Parameters

    • Optional eTag: string

      The E-Tag to parse or something falsy

    Returns null | string

Generated using TypeDoc