H5P NodeJS Library
    Preparing search index...

    Interface ITemporaryFileStorage

    Stores files uploaded by the user in temporary storage. Note that filenames can be paths like 'images/xyz.png'!

    interface ITemporaryFileStorage {
        deleteFile(filename: string, ownerId: string): Promise<void>;
        fileExists(filename: string, user: IUser): Promise<boolean>;
        getFileStats(filename: string, user: IUser): Promise<IFileStats>;
        getFileStream(
            filename: string,
            user: IUser,
            rangeStart?: number,
            rangeEnd?: number,
        ): Promise<Readable>;
        listFiles(user?: IUser): Promise<ITemporaryFile[]>;
        sanitizeFilename(filename: string): string;
        saveFile(
            filename: string,
            dataStream: ReadStream,
            user: IUser,
            expirationTime: Date,
        ): Promise<ITemporaryFile>;
    }

    Implemented by

    Index

    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

    • 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

    • Returns a information about a temporary file. Throws an exception if the file does not exist.

      Parameters

      • filename: string

        the relative path inside the library

      • user: IUser

        the user who wants to access the file

      Returns Promise<IFileStats>

      the file stats

    • 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<Readable>

      the stream containing the file's content

    • Returns a list of files in temporary storage for the specified user. If the user is undefined or null, lists all files in temporary storage.

      Parameters

      • Optionaluser: IUser

        (optional) Only list files for the user. If left out, will list all temporary files.

      Returns Promise<ITemporaryFile[]>

      a list of information about the files

    • 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

      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