image-optimization: how to skip objects that served from the bucket that is not image?

I saw url_rewriter has checks for suffix, but I still get

Input buffer contains unsupported image format when i try to visit a txt or pdf file.

How to make the function skip objects without image suffix?

Thanks

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 15 (5 by maintainers)

Most upvoted comments

@gxolin thanks for adding to this. I want to point out, however, this is talking about user uploaded files, not site assets. Separating site assets from user uploads can be done during development and as such I think it’s easier than distinguishing image uploads from non-image ones. Of course YMMV depending on framework etc.

@achrafsouk what do you think about adding this config, maybe behind a parameter e.g. CLOUDFRONT_FILTER_IMAGES?

@achrafsouk I re-deployed the latest changes in main, and found the CDN responds with a 502 for non-image assets. Indeed, I checked the latest changes and there’s no trace of fixing this. Does closing the issue mean there’s no intention of fixing it, and each developer will have to do it themselves following instructions found here?

We store all user uploaded files in the same bucket. They’re a mix of images and documents (e.g. PDFs) and it would be difficult to store/serve them separately.

I will consider it in the roadmap. Can you tell me what is the application you are using it for?

For the best and optimal solution to avoid processing files other than images by this solution, is to create seperate CloudFront cache behaviors with/without this solution according to your files. For example, you can create behaviors for .*jpg *.png etc extensions and only apply the solution there, and for the default behavior just point to the bucket without any processing.