aws-samples / image-optimization

Simple, performant and cost efficient solution for optimizing images using Amazon CloudFront, Amazon S3 and AWS Lambda
MIT No Attribution
195 stars 116 forks source link

case insensitive acceptance of all variants of an image e.g. .png, .PNG, .Png, .pNG etc. #39

Closed muddassirmunirmakula closed 2 months ago

muddassirmunirmakula commented 5 months ago

Hi @achrafsouk , is there any way we can add case sensitive types too? i.e. I want the cache behaviour to accept all variant cases of png, i.e. PNG, Png, pNG etc. I have tried the following ^..png$, .[png,PNG,Png], .[pP][nN][gG] but all of these result in error: The parameter globPattern can only contain these characters: [a-zA-Z0-9_-.$/~"'&@:?+].

achrafsouk commented 5 months ago

Hwello, This is not possible in the path pattern definition of CloudFront today. Can you tell me why do you need this?

muddassirmunirmakula commented 5 months ago

I see. So I came across a use case where I needed to process an image which has .PNG extension and I was looking for an easier way to resolve this than having to add Cache Behaviours for this and other usecases e.g. JPG, JPEG etc.

piotrekwitkowski commented 2 months ago

@muddassirmunirmakula Please see Path pattern section on Amazon CloudFront Developer Guide.

If the default path pattern (*, capturing all requests) does not work for you, I would suggest deploying the solution on a specific prefix only, for example for paths that start with /images/*.

To stay on the safe side, you can build in additional validation of the file extension against the regex in the viewer request function. If the extension doesn't match the regex, you can return 400 Bad Request response from the function to the clients.