plank / laravel-mediable

Laravel-Mediable is a package for easily uploading and attaching media files to models with Laravel
MIT License
771 stars 101 forks source link

Upload Media on AWS S3 private Bucket #338

Open ciobanugabriel opened 10 months ago

ciobanugabriel commented 10 months ago

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 commented 10 months ago

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 commented 10 months ago

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 commented 9 months ago

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 commented 7 months ago

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