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.

Function code needs to be updated for a bug

See original GitHub issue

Followed the instruction in the development guide below

https://docs.aws.amazon.com/solutions/latest/serverless-image-handler/appendix-d.html

Trying to convert my image with filter, it works fine if there is no prefix in my image uploaded in S3 bucket. (no prefix means that my image is not under a folder. any folder structure means only a prefix to an object due to S3 is an object storage without folder concept)

However, it does not work if there is a prefix in my object (image file)

##Works

https://d3q88at0v19ygp.cloudfront.net/fit-in/300x400/filters:fill(00ff00):rotate(90)/<example>.jpg

##Not works

https://d3q88at0v19ygp.cloudfront.net/fit-in/300x400/filters:fill(00ff00):rotate(90)/<object prefix>/<example>.jpg

After checked the source code provided by the solution, the function code listed below which requires modification. Otherwise, it cannot work if there is a prefix in customer’s s3 object when using the scenario mentioned in[1]

https://github.com/awslabs/serverless-image-handler/blob/master/source/image-handler/image-request.js#L141

According to the function, it always returned only object key without prefix ( ==> return key[key.length - 1]; ), which is the reason why filter cannot work especially when I enter an object key with prefix from a S3 bucket.

Suggest to remove following syntax

const key = (event["path"]).split("/");
return key[key.length - 1];

Replace with following code, the repack the code deployment package and re-upload to the function. I will submit the feedback to the doc

var path = event["path"];
const match_reg1 = new RegExp(/^(\/?)((fit-in)\/\d+x\d+\/(filters:.+)(unsafe)?).*(.+jpg|.+png|.+webp|.+tiff|.+jpeg)$/);
const match_reg2 = new RegExp(/^(\/?)((fit-in)\/\d+x\d+\/(smart)(unsafe)?).*(.+jpg|.+png|.+webp|.+tiff|.+jpeg)$/);


 var updatedKey = '';
 const key = path.split("/");
 
if (match_reg1.test(path) || match_reg2.test(path)) {

   for (i = 4; i < key.length; i++) { 
     updatedKey += key[i];
     if (i != key.length-1){
       updatedKey += '/';
     }
   }
   console.log(updatedKey);
   return updatedKey;
 }
 
 else{
   for (i = 3; i < key.length; i++) { 
     updatedKey += key[i];
     if (i != key.length-1){
       updatedKey += '/';
     }
   }
   
   console.log(updatedKey);
   return updatedKey;
 }

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:8 (5 by maintainers)

github_iconTop GitHub Comments

3reactions
damien-monnicommented, Jun 19, 2019

I also have the exact same problem. It doesn’t work with the Thumbor syntax, but it does with the image request syntax as JSON.

Working with images nested in subfolders is only supported using the v4.0.0 image request syntax

@hayesry, there are 2 problems for me using the encoded JSON object:

  1. SEO: original filename doesn’t appear in URL anymore
  2. SSR : I wanted to use it on a React application with Server Side Rendering (using Next.js), so I need a polyfill for btoa() function.
0reactions
beomseokleecommented, Feb 6, 2020

We are closing this issue, but please feel free to open the issue again if you any other support.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Lambda Update Function Code Fails · Issue #2984 - GitHub
Describe the bug Within the past week, attempting to use the AWS Toolkit to Update Function Code for Lambda fails stating that 'An...
Read more >
javascript - Which function in code has bug and how to fix the ...
javascript - Which function in code has bug and how to fix the code to work properly again - Stack Overflow. Stack Overflow...
Read more >
Bugs and Errors :: Eloquent JavaScript
Flaws in computer programs are usually called bugs. It makes programmers feel good to imagine them as little things that just happen to...
Read more >
9 techniques for fixing bugs in production - TechTarget
IT organizations have many ways of fixing bugs in production. ... Microservices enable them to fix issues with minor code changes and less ......
Read more >
When one bug leads to another | Phase2 Technology
All code has bugs · Code which is changed by tired developers pushing for a release is even more likely to have bugs...
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