backend
    Preparing search index...

    Class S3Service

    Index

    Constructors

    • Parameters

      • configService: ConfigService

        The configuration service for retrieving S3 configuration values. Its from s3.config.ts which is a nestjs/config package and is used to access environment variables and other configuration settings required for S3 operations.

      Returns S3Service

      Initializes the S3Service by setting up the S3 client and bucket names based on the provided configuration. The constructor retrieves necessary configuration values such as AWS credentials, region, endpoint, and bucket names for different types of images (book covers, author images, profile pictures). If any required configuration value is missing, an error will be thrown during initialization.

    Methods

    • Parameters

      • bucket: "author" | "book" | "profile"

        The type of bucket from which to delete images ('author', 'book', or 'profile').

      • fileKeys: string[]

        File keys to delete

      Returns Promise<void>

      Deletes images from the specified S3 bucket based on the provided file keys. The method checks if the file keys are valid and limits the number of keys to prevent excessive deletions. If any error occurs during the deletion process, an InternalServerErrorException is thrown.

      BadRequestException if the number of file keys exceeds the allowed limit.

      InternalServerErrorException if an error occurs during the deletion process.

    • Sharp for image processing and upload to S3

      Parameters

      • file: UploadedFile

        Multer file object

      • bucket: "author" | "book" | "profile"

        bucket type ('author' | 'book' | 'profile')

      • title: string

        Image name base for generating file names

      Returns Promise<{ keys: string[]; large: string; small: string }>

      An object containing URLs and keys of the uploaded images

      This method takes an uploaded file, processes it using Sharp to create different sizes based on the specified bucket type, and uploads the processed images to S3. The method generates unique file names to avoid collisions and returns the URLs and keys of the uploaded images. If any error occurs during processing or uploading, an InternalServerErrorException is thrown.

      BadRequestException if the bucket type is invalid.

      InternalServerErrorException if an error occurs during image processing or upload to S3.