serverless-image-handler icon indicating copy to clipboard operation
serverless-image-handler copied to clipboard

Unable to parse S3 Key with prefix under Thumbor mode

Open salander0411 opened this issue 6 years ago • 6 comments

example:

  • URL that could be parsed correctly: https://xxxxx.cloudfront.net/fit-in/400x400/filters:watermark(test,random.jpg,0,0)/lena.jpg

  • URL that couldn't be parsed: https://xxxxx.cloudfront.net/fit-in/400x400/filters:watermark(test,test/random.jpg,0,0)/lena.jpg be

That looks like is due to

        if (requestType === "Thumbor" || requestType === "Custom") {
            return decodeURIComponent(event["path"].replace(/\d+x\d+\/|filters[:-][^/;]+|\/fit-in\/+|^\/+/g,'').replace(/^\/+/,''));
        }

the regex will lead the key to be 'random.jpg,0,0)/lena.jpg '

in parseImageKey in image-request.js

salander0411 avatar Aug 21 '20 04:08 salander0411

@salander0411 Thanks for contacting us, and thanks for your feedback. We'll investigate this issue and get back to you.

beomseoklee avatar Aug 21 '20 18:08 beomseoklee

Thanks @beomseoklee , any update?

salander0411 avatar Aug 25 '20 07:08 salander0411

@salander0411 I think this would work. Not fully tested though.

\d+x\d+\/|filters:.+(.?\))|\/fit-in\/+|^\/+

So maybe the source code you provided can be replaced to

        if (requestType === "Thumbor" || requestType === "Custom") {
            return decodeURIComponent(event["path"].replace(/\d+x\d+\/|filters:.+(.?\))|\/fit-in\/+|^\/+/g,'').replace(/^\/+/,''));
        }

I'm still testing it.

beomseoklee avatar Aug 25 '20 23:08 beomseoklee

The key could be parsed correctly but the overlay image key cannot be parsed now.

https://xxxxx.cloudfront.net/fit-in/400x400/filters:watermark(test,random.jpg,0,0)/lena.jpg

orginal image could be parsed to be: https://xxxxx.cloudfront.net/lena.jpg

but the overlay image key now parsed to be : filters:watermark(oss-to-s3-test,

salander0411 avatar Sep 03 '20 08:09 salander0411

Looking forward for your update, thanks!

salander0411 avatar Sep 22 '20 08:09 salander0411

Thanks for waiting @salander0411 We've fixed this issue in v5.1.0.

beomseoklee avatar Nov 19 '20 19:11 beomseoklee