0

I have Laravel backend with Intervention package to handle images. All images are stored in S3 bucket and are accessed through CDN - Cloudfront distribution.

When user requests image from my app I use something like this line to fetch image and return it to user.

 return Image::make("https://*********.cloudfront.net/S3_image_path_and_filename.jpg")->response()->header('Cache-Control', 'max_age=3600');

This code worked without any troubles for more than a year without any changes but recently I started to see that some images on client side are empty and there are errors saying

Intervention\Image\Exception\NotReadableException Unable to init from given url

I looked up for issues with missing images but they exist in S3 bucket and are accessible through Cloudfront. I even see them on client side after clearing cache or waiting for some time - so this issue is flacky, can't reproduce it. I even don't see any error associated with images in Cloudfront distribution.

My questions are

  1. what could be the reasons behind this issue?
  2. how I can debug it?
  3. maybe I need to handle the exception above but I am not sure what should be returned to user in that case?
moonvader
  • 19,761
  • 18
  • 67
  • 116
  • [this](https://stackoverflow.com/questions/42364200/unable-to-init-from-given-url-in-intervention-image-2-3) question seems to imply a simple retry might work. You might be tripping some DDoS protection on cloudfront that rejects some of your requests. – apokryfos Sep 09 '22 at 06:51
  • thank you, saw this workaround. would like also to understand the root cause of this issue. – moonvader Sep 09 '22 at 08:13
  • 1
    Unfortunately I don't see a decent way to debug this easily. [the code that throws that exception](https://github.com/Intervention/image/blob/master/src/Intervention/Image/AbstractDecoder.php#L66) seems to suppress the actual issue so that information is lost. As soon as you get an error like that you can try to do run a `file_get_contents` (with similar context) or a cURL request to see if you get an error hopefully with more detail. – apokryfos Sep 09 '22 at 08:31

0 Answers0