title: AWS S3 Presigned Request Cache
body: <p>I want to store user profile pictures in an S3 bucket, but keep these images private. In order to do this, I am creating a presigned url whenever the image is required. However, this creates a unique url each time which means the image will never be cached by the browser and I'll end up paying a lot more in GET requests.</p>
  
  <p>Here's an example of my code to generate the url, I'm using Laravel: </p>
  
  <pre><code>$s3 = \Storage::disk('s3');
  $client = $s3-&gt;getDriver()-&gt;getAdapter()-&gt;getClient();
  $expiry = new \DateTime('2017-07-25');
  
  $command = $client-&gt;getCommand('GetObject', [
      'Bucket' =&gt; \Config::get('filesystems.disks.s3.bucket'),
      'Key'    =&gt; $key
  ]);
  
  $request = $client-&gt;createPresignedRequest($command, $expiry);
  
  return (string) $request-&gt;getUri();
  </code></pre>
  
  <p>I thought that by specifying a datetime rather a unit of time that it would create the same url but it actually adds the number of seconds remaining to the url, here's an example:</p>
  
  <blockquote>
    <p>xxxx.s3.eu-west-2.amazonaws.com/profile-pics/92323.png?X-Amz-Content-Sha256=UNSIGNED-PAYLOAD&amp;X-Amz-Algorithm=AWS4-HMAC-SHA256&amp;X-Amz-Credential=AXXXXXXXXXXX%2Feu-west-2%2Fs3%2Faws4_request&amp;X-Amz-Date=20170720T112123Z&amp;X-Amz-SignedHeaders=host&amp;X-Amz-Expires=391117&amp;X-Amz-Signature=XXXXXXXXX</p>
  </blockquote>
  
  <p><strong>Is it possible to generate a repeatable presigned request url so that an image may be cached by the users browser?</strong></p>