4

I'm using Multer with Express and I'm trying to retrieve image dimensions (width and height) before I upload the image to AWS S3.

My goal is to validate the image by image size, image type and image dimensions. Image size and image type can be validated with built in Multer methods but unfortunately image dimensions cannot be retrieved without saving the image beforehand.

Currently, I am saving the image locally, then I retrieve said image's dimensions and then, depending on the height and width values, I decide if I should upload the image to S3.

I am trying to avoid saving the image locally just to retrieve its dimensions and then deleting it once it's uploaded to S3 but I'm not sure if that's possible using Multer since I can't seem to find a way to access the file until it is actually uploaded.

Any help is appreciated.

hakaman
  • 181
  • 1
  • 6

1 Answers1

0

I am not sure if this would help you, but you can try and upload the image in a temporary folder which allows you to have access to the image dimensions.
Then you extract the dimensions and validate it.
If it meets your requirement, then you upload to S3. If not, you remove it.

You can visit this page here for other ways to do this. It might help.

סטנלי גרונן
  • 2,740
  • 21
  • 43
  • 62
OLAWALE
  • 1
  • 3