-2

As per our project requirements we need to save artworks (images with JPG, PNG, TIFF etc image formats) which can size anywhere from 1KB to 1MB. We are now storing them in AWS S3 bucket.

I have below few questions on our implementation:

  1. Is it a good solution to store all the images in AWS S3 bucket?
  2. Can I directly fetch a thumbnail from AWS S3 bucket for all the image files? If yes, how can I fetch that thumbnail?
  3. Can I create a thumbnail (of size ~1KB) every time I upload an image and store the byte array in RDBMS? (This is just to avoid fetching the image content from S3 bucket, because those thumbnails are used just for preview purposes)
  4. Can I compress the images in java? How to do that so that I get the least minimal byte size?
John Rotenstein
  • 241,921
  • 22
  • 380
  • 470

2 Answers2

0

Amazon S3 is a good service to store images because there is no limit on the amount of storage and the files can be made accessible on the Internet (rather than having to serve them via your app).

There is no in-built capability for Amazon S3 to create a thumbnail. You might consider triggering an AWS Lambda function when a new image is stored in the S3 bucket. See: Tutorial: Using AWS Lambda with Amazon S3

It would be more efficient to store the thumbnail in Amazon S3 rather than a database. When creating an HTML page with a preview icon, simply point to the icon image in Amazon S3. The user's browser will then fetch it directly from S3 rather than your app having to retrieve and serve the image.

If you wish to control access to the images and thumbnails, use Amazon S3 pre-signed URLs to grant time-limited access to private objects.

An alternative to creating your own thumbnails is to use one of the thumbnail-as-a-service offerings such as:

John Rotenstein
  • 241,921
  • 22
  • 380
  • 470
0
import java.awt.*;
import javax.imageio.*;
import org.imgscalr.Scalr;

void createThumbnailUsingScalr(File sourceImage) throws Exception {
        File destImage =
                new File("/Path/For/Destination/Thubnail.png");
            BufferedImage img = ImageIO.read(sourceImage);
            BufferedImage thumbImg = Scalr.resize(img, Scalr.Method.QUALITY, Scalr.Mode.AUTOMATIC, 200, 200, Scalr.OP_ANTIALIAS);
            ImageIO.write(thumbImg, "PNG", destImage);
    }

This above code is little bit helping my needs