Search code examples
laravelamazon-s3laravel-storage

Errors while getting many images from S3 Laravel Storage


One of my API's routes associated with Laravel controller that returns URL of image stored on AWS S3.

I have function that looks like

public function getImage($params) {
  //... $image is fetched from database
  return Storage::disk('s3')->response("some_path/".$image->filename);
}

This codes works fine when I'm requesting few images, but when I try to use it inside some list which can be scrolled very fast some of request are failing. What am I doing wrong?


Solution

  • Because you are quickly scrolling and populating your lists, a lot of requests are being made to your server.

    Laravel has a throttle middleware installed by default on your routes to mitigate security risks.

    In your case you are hiring the limits of the throttle, resulting in 429 error codes.

    Your PHP code is correct, your front-end code should be less greedy in trying to fetch images.

    .... Or you should raise the allowed throttle amount in laravel, or remove it all together, but I wouldn't recommend it.