Directus Storage Adapter AWS S3 error: No permission to write:

1.3k Views Asked by At

I decided to use Directus as a Headless CMS in one of our projects. For storing media files we decided to use AWS S3 as a storage adapter. I have followed all instructions from Directus documentation how to setup the configurations for S3 but i am keeping on getting this error:

message: "No permission to write: 122d303f-b69a-48f8-8138-8f3404b3c992.jpg"

I have tried the AWS S3 bucket from CLI commands, and i can upload files there and list the files but from Directus i am having the no permission to write error.

Storage configuration in Directus looks like this:

 'storage' => [
    'adapter' => 's3',      // What storage adapter to use for files
                            // Defaults to the local filesystem. Other natively supported
                            // options include: Amazon S3, Aliyun OSS, Azure
                            // You'll need to require the correct flysystem adapters through Composer
                            // See https://docs.directus.io/extensions/storage-adapters.html#using-aws-s3
    'root' => '/originals',          // Where files are stored on disk
    'thumb_root' => '/thumbnails',    // Where thumbnails are stored on disk
    'root_url' => '##S3_URL##/originals',            // Where files are accessed over the web        
    // 'proxy_downloads' => false, // Use an internal proxy for downloading all files
    // S3
    ////////////////////////////////////////
    'key'    => '##S3_KEY##',
    'secret' => '##S3_SECRET##',
    'region' => '##S3_REGION##',
    'version' => 'latest',
    'bucket' => '##S3_BUCKET##',
    'options' => [
       'ACL' => 'public-read',
       'CacheControl' => 'max-age=604800'
    ],
],

Anyone can give any insight on this?

Thanks in advance.

2

There are 2 best solutions below

1
On

I had the same issue. In my case, I've allowed "s3:PutObjectAcl" on the bucket and it starts working :) It seems that this is a flysystem issue.

0
On

Need to add the following

'options' => [
    'ACL' => 'private',
],

I found that I did not need the bucket policy update. Just need to add this to the config.php when trying to upload to a private bucket.