question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

images in subfolders doesn't work

See original GitHub issue

you may try this yourself to reproduce

I tried this solution by putting test.jpg in root of the bucket - works perfect eg. test123.com/test.jpg is the path location test123.com/300x300/smart/diwali.jpg - works perfect

try the same image test.jpg in a subfolder of the same bucket - doesn’t work, says keys not present eg. test123.com/folder1/folder2/test.jpg is the path location test123.com/300x300/smart/folder1/folder2/test.jpg - doesn’t work

error in cloud watch

2019-06-23T09:05:46.801Z	f8642cb7-0584-4b30-9313-27aee17205c0	ImageRequest {
requestType: 'Thumbor',
bucket: 'xxx.xxxx.x.xxx',
key: 'test.jpg',
edits: { resize: { width: 300, height: 300 } },
originalImage: <Buffer ff d8 ff e0 00 10 4a 46 49 46 00 01 01 01 01 2c 01 2c 00 00 ff e1 00 d7 45 78 69 66 00 00 49 49 2a 00 08 00 00 00 01 00 0e 01 02 00 b5 00 00 00 1a 00 ... > }

looks like while retrieving the key:

    parseImageKey(event, requestType) {
        if (requestType === "Default") {
            // Decode the image request and return the image key
            const decoded = this.decodeRequest(event);
            return decoded.key;
        } else if (requestType === "Thumbor" || requestType === "Custom") {
            // Parse the key from the end of the path
            const key = (event["path"]).split("/");
            return key[key.length - 1];
        } else {
            // Return an error for all other conditions
            throw ({
                status: 400,
                code: 'ImageEdits::CannotFindImage',
                message: 'The image you specified could not be found. Please check your request syntax as well as the bucket you specified to ensure it exists.'
            });
        }
    }

it should fetch based on /smart/ context root instead of default / . what do you think ?

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:5
  • Comments:21 (2 by maintainers)

github_iconTop GitHub Comments

15reactions
harrybaileycommented, Jul 24, 2019

I’m in exactly the same boat as @soupy1976 here. Old version died due to environment changes. New version fails with anything outside the root of the bucket.

I would happily move to Sharp from Thumbor, but Sharp won’t layer images based on absolute remote urls.

So here we are.

My fix was:

  • Go to the Lambda function
  • Select ‘Actions’ then ‘Export Function’
  • Unzip the download and open ‘image-request.js’
  • Update the parseImageKey method to the following:
parseImageKey(event, requestType) {
        if (requestType === "Default") {
            // Decode the image request and return the image key
            const decoded = this.decodeRequest(event);
            return decoded.key;
        } else if (requestType === "Thumbor" || requestType === "Custom") {
            // Parse the key from the end of the path
            const pathParts = (event["path"]).split("/");

            for (let i = 0; i < pathParts.length; i++) {

                if (
                    pathParts[i] !== ''
                    && pathParts[i] !== 'fit-in'
                    && pathParts[i].match(/^\d+x\d+$/) == null
                    && pathParts[i].match(/^filters:/) == null
                ) {
                    const parts = pathParts.slice(i);
                    return (parts.join('/'));
                }
            }
        }

        // Return an error for all other conditions
        throw ({
            status: 400,
            code: 'ImageEdits::CannotFindImage',
            message: 'The image you specified could not be found. Please check your request syntax as well as the bucket you specified to ensure it exists.'
        });
    }
  • Save the file
  • Zip the contents of the folder (not the folder itself)
  • Back on your Lambda function page, select to upload a zip
  • Choose the new zip file
  • Once uploaded select ‘save’
  • Wait for it to finish updating and reload your test url

What the code essentially does it look for anything which isn’t likely to be the start of a path, and once it no longer finds one it puts the remaining parts of the url into the returned key.

Not heavily tested, but works with image paths in the form: https://[your path].cloudfront.net/fit-in/600x0/filters:blur(7)/prod/12345.jpg Where the bucket path is prod/12345.jpg

5reactions
dyarbroughcommented, Jul 19, 2019

This solution is unusable for us without the ability to use subfolders.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Windows 10 Photos will not show pictures in subfolders..........
Type troubleshoot in Windows Start Search box > Click Troubleshoot > Scroll down to bottom and click Windows Store Apps > Click Run...
Read more >
Cannot access image in subfolders - html - Stack Overflow
I have the same problem as well. For some reason the same directory works but subdirectories don't work. Perhaps use webpack? – Rouli...
Read more >
images in subfolders doesn't work · Issue #112 - GitHub
try the same image test.jpg in a subfolder of the same bucket - doesn't work, says keys not present eg. test123.com/folder1/folder2/test.jpg ...
Read more >
Windows 10 Background Slideshow Not Seeing Subfolders
Method 3: Using File Explorer to create a desktop background slideshow · Open File Explorer and navigate to the main image folder (the...
Read more >
How to browse through all images from different subfolders
Download, install and run IrfanView. · Drag and drop the parent folder from Windows Explorer into the IrfanView window, which opens IrfanView ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found