Prateek Srivastava's avatar

How to add headers (Expires, CacheControl) to a file uploaded to Amazon S3 using the Laravel 7.30.4 Storage facade

I am trying to find out how to add headers (Expires, CacheControl) to a file uploaded using the Laravel 7.30.4 Storage facade. I am using laravel documentation for reference.

https://laravel.com/docs/8.x/filesystem#caching

0 likes
6 replies
neilstee's avatar

@prateek srivastava

Storage::disk('s3')->getDriver()->put('/test.txt', 'test', [ 'visibility' => 'public', 'Expires' => 'Expires, Fri, 30 Oct 1998 14:19:41 GMT']);

or configure it inside config/filesystems.php

s3' => [
    'driver' => 's3',
    'key' => env('AWS_KEY'),
    'secret' => env('AWS_SECRET'),
    'region' => env('AWS_REGION'),
    'bucket' => env('AWS_BUCKET'),
    'options' => ['CacheControl' => 'max-age=315360000, no-transform, public', 
                  'ContentEncoding' => 'gzip']
],
1 like
Prateek Srivastava's avatar

@neilstee ,

We are using the same configuration but didn't get any success. Also, max-age is not reflecting in the browser network panel tab.

neilstee's avatar

have you cleared your config when you change config/filesystems.php?

martinbean's avatar

@prateek srivastava Well how are you actually retrieving the file? Those headers are set on HTTP responses; not as metadata on the file itself.

Prateek Srivastava's avatar

We are using the storage facade to upload the files with s3 configuration setup in config/filesystems.php and it's working but we need now to set up the expire headers for the static contents.

see the response in attached screenshot (https://prnt.sc/10dp5vy)

Please or to participate in this conversation.