Keeps track of temporary files (images, video etc. upload for unsaved content).

Constructors

Methods

  • Saves a file to temporary storage. Assigns access permission to the user passed as an argument only.

    Parameters

    • filename: string

      the original filename of the file to store

    • dataStream: ReadStream

      the data of the file in a readable stream

    • user: IUser

      the user who requests the file

    Returns Promise<string>

    the new filename (not equal to the filename passed to the method to unsure uniqueness)

  • Checks if a file exists in temporary storage.

    Parameters

    • filename: string

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

    • user: IUser

      the user for who to check

    Returns Promise<boolean>

    true if file already exists

  • Tries generating a unique filename for the file by appending a id to it. Checks in storage if the filename already exists and tries again if necessary. Throws an H5PError if no filename could be determined.

    Parameters

    • filename: string

      the filename to check

    • user: IUser

      the user who is saving the file

    Returns Promise<string>

    the unique filename

  • Returns a file stream for temporary file. Will throw H5PError if the file doesn't exist or the user has no access permissions! Make sure to close this stream. Otherwise the temporary files can't be deleted properly!

    Parameters

    • filename: string

      the file to get

    • user: IUser

      the user who requests 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<Readable>

    a stream to read from