Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Choose Amazon S3 storage class using Laravel Filesystem

Amazon S3 has different storage classes, with different price brackets.

I was wondering if there's a way I can choose a storage class in Laravel's Filesystem / Cloud Storage solution?

It would be good to choose a class on a per upload basis so I can choose throughout my application, not just once in a configuration file.

like image 355
Wasim Avatar asked Mar 05 '16 12:03

Wasim


People also ask

Does Amazon S3 provide a filesystem?

Amazon S3 is object storage. It is not a file system (eg C:\ drive). Rather, applications can place API calls to upload/download data. Amazon S3 can also make objects available via HTTP/s without having to run a web server.

What is the default S3 storage class?

For performance-sensitive use cases (those that require millisecond access time) and frequently accessed data, Amazon S3 provides the following storage classes: S3 Standard — The default storage class. If you don't specify the storage class when you upload an object, Amazon S3 assigns the S3 Standard storage class.


2 Answers

To pass additional options to flysystem you have to use getDriver()

Storage::disk('s3')->getDriver()->put(
    'sample.txt',
    'This is a demo',
    [
        'StorageClass' => 'REDUCED_REDUNDANCY'
    ]
);
like image 89
Adam Avatar answered Sep 29 '22 14:09

Adam


This can be used in Laravel 7

Storage::disk('s3')->put(
    'file path',
    $request->file('file'),
    [
        'StorageClass' => 'STANDARD|REDUCED_REDUNDANCY|STANDARD_IA|ONEZONE_IA|INTELLIGENT_TIERING|GLACIER|DEEP_ARCHIVE',
    ]
);

You can use putFileAs() Method As Well Like Below

Storage::disk('s3')->putFileAs(
        'file path',
        $request->file('file'),
        'file name',
        [
            'StorageClass' => 'STANDARD|REDUCED_REDUNDANCY|STANDARD_IA|ONEZONE_IA|INTELLIGENT_TIERING|GLACIER|DEEP_ARCHIVE',
        ]
    );
like image 25
Smith Avatar answered Sep 29 '22 15:09

Smith