Using DigitalOcean Spaces or Amazon S3 for file storage in XF 2.1+

Using DigitalOcean Spaces or Amazon S3 for file storage in XF 2.1+

No permission to download
How can add CNAME record? I have set bucket name attachment.mydomain.info but does not work. Still avatars loading via URL https://attachments.mydomain.info.s3.us-east-1.amazonaws.com/data/avatars/ but How can load via URL https://attachments.mydomain.info/data/avatars/?

attachment.mydomain.info. 14400 CNAME s3.us-east-1.amazonaws.com
 
CNAME is a type of DNS record. You create that in your domain settings in your domain name registrar control pane.
 
CNAME is a type of DNS record. You create that in your domain settings in your domain name registrar control pane.

Not in under cPanel? I am using my own nameservers in cPanel. So all record need add under cPanel, not domain name registrar control panel?

ScreenShot00272.png

Code:
$s3 = function()
{
   return new \Aws\S3\S3Client([
      'credentials' => [
         'key' => '123',
         'secret' => '12345'
      ],
      'region' => 'us-east-1',
      'version' => 'latest',
      'endpoint' => 'https://s3.us-east-1.amazonaws.com'
   ]);
};



$config['fsAdapters']['data'] = function() use($s3)
{
   return new \League\Flysystem\AwsS3v3\AwsS3Adapter($s3(), 'attachments.mydomain.info', 'data');
};



$config['externalDataUrl'] = function($externalPath, $canonical)
{
   return 'https://attachments.mydomain.info.s3.us-east-1.amazonaws.com/data/' . $externalPath;
};



$config['fsAdapters']['internal-data'] = function() use($s3)
{
   return new \League\Flysystem\AwsS3v3\AwsS3Adapter($s3(), 'attachments.mydomain.info', 'internal_data');
};
 
Last edited:
If it's just a case of the URL displaying wrong, then you likely just need to update this line in your config:

PHP:
   return 'https://attachments.mydomain.info.s3.us-east-1.amazonaws.com/data/' . $externalPath;

Presumably you're expecting it to be:

PHP:
   return 'https://attachments.mydomain.info/data/' . $externalPath;
 
If it's just a case of the URL displaying wrong, then you likely just need to update this line in your config:

PHP:
   return 'https://attachments.mydomain.info.s3.us-east-1.amazonaws.com/data/' . $externalPath;

Presumably you're expecting it to be:

PHP:
   return 'https://attachments.mydomain.info/data/' . $externalPath;

Image are not showing with this change. Only showing blank user avatars.
 
Then there's something wrong with the DNS record or your bucket configuration.

One more think. What are correct setup for DNS?

attachment.mydomain.info. 14400 CNAME s3.amazonaws.com

OR

attachment.mydomain.info. 14400 CNAME s3.us-east-1.amazonaws.com

OR

attachment.mydomain.info. 14400 CNAME attachments.mydomain.info.s3.us-east-1.amazonaws.com
 
I don't know to be honest. Your best bet is to check with the Amazon S3 documentation. You have to add the DNS record to their requirements and I don't know what those requirements are.
 
Hi.

In order for my S3 Bucket to work, I un-blocked all public access.

Is this correct? Or should some of these options be checked?

Block Public Access.JPG

Or is there another setting I should have been using instead?

Thanks!
 
did you created the S3 Name along the requirements if you want to set a CNAME domain record to it?


It should be attachments.yourdomain.info as bucket Name.

Yes but does not work. I think we need add Custom Hostname in AWS S3 for SSL certificate but where?

How can add CNAME record? I have set bucket name attachment.mydomain.info but does not work. Still avatars loading via URL https://attachments.mydomain.info.s3.us-east-1.amazonaws.com/data/avatars/ but How can load via URL https://attachments.mydomain.info/data/avatars/?

attachment.mydomain.info. 14400 CNAME s3.us-east-1.amazonaws.com
 
Or is there another setting I should have been using instead?
I personally am using two S3 buckets, the default data bucket is public, and the internal is restricted.
But thats not neccesary, afaik the System sets the restriction for internal files that they are not visible to the public.
So, that looks correct, yes. But check if the internal-data is really protected from the public.
Sorry for the german screenshot. But only the top entry should have access.
1623250909078.webp
 
Yes but does not work. I think we need add Custom Hostname in AWS S3 for SSL certificate but where?
I only set these things up, and it works out of the box.
I just realizes that you
attachment.mydomain.info.14400CNAMEattachments.mydomain.info.s3.us-east-1.amazonaws.com
are typing on the bucket name singular, and in the CNAME Settings plural. You should remove or add the S, based on what is correct.
 
I only set these things up, and it works out of the box.
I just realizes that you

are typing on the bucket name singular, and in the CNAME Settings plural. You should remove or add the S, based on what is correct.

Done but issue are same.


attachments.mydomain.info. 14400 CNAME attachments.mydomain.info.s3.us-east-1.amazonaws.com
 
Top Bottom