I have an S3 bucket that is used to store files via Laravel. I have updated the bucket policy to use a Customer-Managed CMK and I cannot figure out or find what configuration to use in Laravel
This is what I have in config/filesystems and it works fine with a standard bucket policy and AWS-Managed CMK
's3' => [
'driver' => 's3',
'key' => env('AWS_ACCESS_KEY_ID'),
'secret' => env('AWS_SECRET_ACCESS_KEY'),
'region' => env('AWS_DEFAULT_REGION'),
'bucket' => env('AWS_BUCKET'),
'url' => env('AWS_URL'),
'endpoint' => env('AWS_ENDPOINT'),
'options' => [
'ServerSideEncryption' => env('AWS_SERVER_SIDE_ENCRYPTION'),
],
],
What changes do I have to make to be able to use a Customer-Managed CMK?
It's not clear what exactly you are passing as ServerSideEncryption as you are getting it from an env var, but this are the options available in the PHP SDK for PutObject:
'SSEKMSKeyId' => '<string>',
'ServerSideEncryption' => 'AES256|aws:kms',
Based on that I believe that your configuration should look like this:
's3' => [
'driver' => 's3',
'key' => env('AWS_ACCESS_KEY_ID'),
'secret' => env('AWS_SECRET_ACCESS_KEY'),
'region' => env('AWS_DEFAULT_REGION'),
'bucket' => env('AWS_BUCKET'),
'url' => env('AWS_URL'),
'endpoint' => env('AWS_ENDPOINT'),
'options' => [
'ServerSideEncryption' => 'aws:kms',
'SSEKMSKeyId' => env('SSE_KMS_KEY_ARN')
],
],
where SSE_KMS_KEY_ARN is the ARN of the KMS CMK key with which you want to encrypt.
Related
I have the issue with storage/uploads/my-folder-name
Everything works perfect in local, but I get broken image icon on the web
I save my links to each image in DB as 'storage/uploads/my-folder-name/file.jpg'
But if I change this path to 'storage/app/public/uploads/my-folder-name/file.jpg' the image is shown correctly
I try to show the image in yajra datatable
I have deleted the storage folder from my public folder and created symbolic link again
So everything should be working but it is not
The filesystem:
'default' => env('FILESYSTEM_DISK', 'local'),
'disks' => [
'local' => [
'driver' => 'local',
'root' => storage_path('app'),
'throw' => false,
],
'public' => [
'driver' => 'local',
'root' => storage_path('app/public'),
'url' => env('APP_URL').'/storage',
'visibility' => 'public',
'throw' => false,
],
's3' => [
'driver' => 's3',
'key' => env('AWS_ACCESS_KEY_ID'),
'secret' => env('AWS_SECRET_ACCESS_KEY'),
'region' => env('AWS_DEFAULT_REGION'),
'bucket' => env('AWS_BUCKET'),
'url' => env('AWS_URL'),
'endpoint' => env('AWS_ENDPOINT'),
'use_path_style_endpoint' => env('AWS_USE_PATH_STYLE_ENDPOINT',
false),
'throw' => false,
],
],
'links' => [
public_path('storage') => storage_path('app/public'),
],
Trying to setup Laravel to access an AWS S3 Multi Region Access Point but can't seem to find anything online about it, is this possible? And if so then how?
I assume I need to update the s3 config for filesystem but can't find the options for it anywhere, any help is appreciated.
's3' => [
'driver' => 's3',
'key' => env('AWS_ACCESS_KEY_ID'),
'secret' => env('AWS_SECRET_ACCESS_KEY'),
'region' => env('AWS_DEFAULT_REGION'),
'bucket' => env('AWS_BUCKET'),
'url' => env('AWS_URL'),
'endpoint' => env('AWS_ENDPOINT'),
'use_path_style_endpoint' => env('AWS_USE_PATH_STYLE_ENDPOINT', false),
'throw' => true,
],
Thanks!
When I add a restaurant/upload an image using voyager. The image displays correctly on user side but doesn't show on admin side. when i inspect the url of the image it shows "app/public" is repeating twice.
If I update the restaurant info and let the image be the same. then it even stops working on the user side too. After inspecting the URL i got to know that the "app/public" keeps repeating the number of time i update the restaurant.
Images directory
public_html/tmo_api/storage/restaurants/July2021
**I've already tried symlinking again. and cache clear etc...
**
Voyager.php
/*'storage' => [
'disk' => env('FILESYSTEM_DRIVER', 'public'),
],*/
'storage' => [
'disk' => 'voyager',
],
filesystems.php
'disks' => [
'local' => [
'driver' => 'local',
'root' => storage_path('app'),
],
'public' => [
'driver' => 'local',
'root' => storage_path('app/public'),
'url' => env('APP_URL').'/storage/app/public',
'visibility' => 'public',
],
's3' => [
'driver' => 's3',
'key' => env('AWS_ACCESS_KEY_ID'),
'secret' => env('AWS_SECRET_ACCESS_KEY'),
'region' => env('AWS_DEFAULT_REGION'),
'bucket' => env('AWS_BUCKET'),
'url' => env('AWS_URL'),
],
'voyager' => [
'driver' => 'local',
'root' => storage_path('app/public'),// change here something specific to your application need
'url' => env('APP_URL').'/storage/app/public',
'visibility' => 'public',
],
],
app.php
'url' => env('APP_URL', 'http://example.com/tmo_api'),
'asset_url' => env('ASSET_URL', null),
.env
APP_NAME=Laravel
APP_ENV=local
APP_KEY=base64:sdfswm8pJN6QQls+sdfRfsd56NQw8XBsdsdfdSW/saVPQ=
APP_DEBUG=true
APP_URL=http://example.com/tmo_api
You can see it repeating on ID-6
In the config/filesytems.php, the default settings is like this
's3' => [
'driver' => 's3',
'key' => env('AWS_ACCESS_KEY_ID'),
'secret' => env('AWS_SECRET_ACCESS_KEY'),
'region' => env('AWS_DEFAULT_REGION'),
'bucket' => env('AWS_BUCKET'),
'url' => env('AWS_URL'),
],
Now, in development, there's only 1 bucket shared by all developers.
Is it possible to add a prefix (as a subfolder) to the config file?
For example
's3' => [
...
'prefix' => 'jslim/',
],
How can I achieve this?
The configuration option you're looking for is called root:
'disks' => [
's3' => [
'root' => 'jslim/',
// 'root' => env('S3_PREFIX', env('APP_ENV') . '/'),
],
],
Hope that helps.
Please give me an example to store files to AWS S3 in laravel 5.5.
I already configured filesystem file with AWS credentials.
I saw the function
Storage::put('file.jpg', $contents);
but don't know what the second parameter is
the contents of filesystem.php file is as follows
return [
'default' => env('FILESYSTEM_DRIVER', 'local'),
'cloud' => env('FILESYSTEM_CLOUD', 's3'),
'disks' => [
'local' => [
'driver' => 'local',
'root' => storage_path('app'),
],
'public' => [
'driver' => 'local',
'root' => storage_path('app/public'),
'url' => env('APP_URL').'/storage',
'visibility' => 'public',
],
's3' => [
'driver' => 's3',
'key' => '*********',
'secret' => '******',
'region' => 'my region',
'bucket' => 'bucketname',
],
],
];
thanks in advance
There is good example in Laravel documentation:
Storage::disk('s3')->put('avatars/1', $fileContents);
The 2nd parameter is is file content so in real life it could look like this:
Storage::disk('s3')->put('file.jpg', file_get_contents('your_local_file.jpg');