This class stores temporary files in a S3-compatible storage system.

IMPORTANT: The expiration (and automatic deletion) of files must be handled on bucket level. See https://aws.amazon.com/de/blogs/aws/amazon-s3-object-expiration/ for details.

You can call the method setBucketLifecycleConfiguration(...) to set up a lifecycle configuration for the expiration time set in the config or you can set up the policy in a more customized way manually.

Implements

Constructors

  • Parameters

    • s3: S3
    • options: {
          invalidCharactersRegexp?: RegExp;
          maxKeyLength?: number;
          s3Acl?: ObjectCannedACL;
          s3Bucket: string;
      }
      • 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.

      • OptionalmaxKeyLength?: number

        Indicates how long keys in S3 can be. Defaults to 1024. (S3 supports 1024 characters, other systems such as Minio might only support 255 on Windows).

      • Optionals3Acl?: ObjectCannedACL

        The ACL to use for uploaded content files. Defaults to private. See the S3 documentation for possible values.

      • s3Bucket: string

        The bucket to upload to and download from. (required)

    Returns S3TemporaryFileStorage

Methods

  • Deletes the file from temporary storage. Throws errors of something goes wrong.

    Parameters

    • filename: string

      the file to delete

    • _ownerId: string

    Returns Promise<void>

  • Returns a readable for a file.

    Note: Make sure to handle the 'error' event of the Readable! This method does not check if the file exists in storage to avoid the extra request. However, this means that there will be an error when piping the Readable to the response if the file doesn't exist!

    Parameters

    • filename: string
    • user: IUser
    • 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>

  • Theoretically lists all files either in temporary storage in general or files which the user has stored in it.

    In the S3 implementation the method is not implemented, as S3 supports file expiration on the bucket level. This feature should be used instead of manually scanning for expired files.

    Parameters

    Returns Promise<ITemporaryFile[]>

  • 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

  • Makes sure the lifecycle configuration of the bucket is set in a way that files automatically expire after the time period set in the the configuration's 'temporaryFileLifetime' property.

    Note: S3's expiration policy only work with full days. The value in the configuration (which can be set in milliseconds) is rounded to the nearest day and will always be at least one day.

    This method will override all existing lifecycle configurations. If you need several custom lifecycle configurations, you must create them manually and NOT use this method.

    Parameters

    Returns Promise<void>