H5P NodeJS Library
    Preparing search index...

    Stores temporary files in directories on the disk. Manages access rights by creating one sub-directory for each user. Manages expiration times by creating companion '.metadata' files for every file stored.

    Implements

    Index

    Constructors

    • Parameters

      • directory: string

        the directory in which the temporary files are stored. Must be read- and write accessible

      • Optionaloptions: { invalidCharactersRegexp?: RegExp; maxPathLength?: number }
        • OptionalinvalidCharactersRegexp?: RegExp

          These characters will be removed from files that are saved to S3. There is a very strict default list that basically only leaves alphanumeric filenames intact. Should you need more relaxed settings you can specify them here.

        • OptionalmaxPathLength?: number

      Returns DirectoryTemporaryFileStorage

    Properties

    options?: { invalidCharactersRegexp?: RegExp; maxPathLength?: number }

    Type declaration

    • OptionalinvalidCharactersRegexp?: RegExp

      These characters will be removed from files that are saved to S3. There is a very strict default list that basically only leaves alphanumeric filenames intact. Should you need more relaxed settings you can specify them here.

    • OptionalmaxPathLength?: number

    Methods

    • Deletes the file from temporary storage (e.g. because it has expired)

      Parameters

      • filename: string

        the filename; can be a path including subdirectories (e.g. 'images/xyz.png')

      • ownerId: string

        (optional) when there is no user deleting, you must specify who the owner of the temporary file is; only needed when userId is null

      Returns Promise<void>

      true if deletion was successful

    • Returns the contents of a file. Must check for access permissions and throw an H5PError if a file is not accessible.

      Parameters

      • filename: string

        the filename; can be a path including subdirectories (e.g. 'images/xyz.png')

      • user: IUser

        the user who accesses the file

      • OptionalrangeStart: number

        (optional) the position in bytes at which the stream should start

      • OptionalrangeEnd: number

        (optional) the position in bytes at which the stream should end

      Returns Promise<ReadStream>

      the stream containing the file's content

    • Removes invalid characters from filenames and enforces other filename rules required by the storage implementation (e.g. filename length restrictions).

      Parameters

      • filename: string

        the filename to sanitize; this can be a relative path (e.g. "images/image1.png")

      Returns string

      the clean filename

    • Stores a file. Only the user who stores the file is allowed to access it later.

      Parameters

      • filename: string

        the filename by which the file will be identified later; can be a path including subdirectories (e.g. 'images/xyz.png')

      • dataStream: ReadStream

        the stream containing the file's data

      • user: IUser

        the user who is allowed to access the file

      • expirationTime: Date

        when the file ought to be deleted

      Returns Promise<ITemporaryFile>

      an object containing information about the stored file; undefined if failed