Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upload Media on AWS S3 private Bucket #338

Open
ciobanugabriel opened this issue Jan 9, 2024 · 4 comments
Open

Upload Media on AWS S3 private Bucket #338

ciobanugabriel opened this issue Jan 9, 2024 · 4 comments
Labels

Comments

@ciobanugabriel
Copy link

I want to store data on AWS S3 in a private bucket to restrict access to media only within the application. For example, I want users to be able to watch a video without being able to download it.

Unfortunately, it only works when I set the bucket to be public. If I set it to private, I receive a 403 response when the MediaUploader attempts to access a file from the bucket.

filesystem.php

'disks' => [

    's3' => [
        'driver' => 's3',
        'key' => env('AWS_ACCESS_KEY_ID'),
        'secret' => env('AWS_SECRET_ACCESS_KEY'),
        'region' => env('AWS_DEFAULT_REGION'),
        'bucket' => env('AWS_BUCKET'),
    ],

'links' => [
    public_path('storage') => storage_path('app/public'),
],

];

mediable.php

'allowed_disks' => [
    'public',
    'local',
    'do',
    's3'
],

Am I doing something wrong, or does the library not allow private media?

@frasmage
Copy link
Collaborator

frasmage commented Jan 9, 2024

The library definitely supports using private buckets. You may need to make sure your IAM settings are correctly configured to allow your application to read and write to the private bucket.

@ciobanugabriel
Copy link
Author

If i`m using like this :
$disk = Storage::disk('s3');
$filePath = 'media/file-test.txt';
$fileContents = 'Hello, this a test!';
$disk->put($filePath, $fileContents);
$fileContent = $disk->get($filePath);
the app is working properly so IAM user have a good acces configuration

@ciobanugabriel
Copy link
Author

The library definitely supports using private buckets. You may need to make sure your IAM settings are correctly configured to allow your application to read and write to the private bucket.

Can you show me a configuration?

@sgtcoder
Copy link

sgtcoder commented Apr 7, 2024

Look at the makePrivate() function call. I had to do this for it to work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants