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
I have problem with tumbnails and avatars on 2.1
images attached to publications look good, but the avatars and thumbnails in the gallery don't work
I think it's because of the cache, I was able to fix the thumbnails in the gallery by regenerating the miniatures

but I don't know how to do this for the avatars
the links of the avatars are like this

Captura de pantalla 2020-10-26 a las 21.16.22.png
 
Last edited:
Yes.

You have to copy the files back to your server (similar process and advice as per copying existing files to AWS in the first place) and then undo any src/config.php changes.
 
I found a bug @Chris D
If you Installed the add-on and then configured in config.php, all goes smooth, but then you disable the add-on and then enable it again, bug appears
Anyone notice to this bug? I have deleted and created new Space to test several times, and bug it just keep repeating, so I can assure this is a bug

Error: Class 'League\Flysystem\AwsS3v3\AwsS3Adapter' not found in src/config.php at line 26
  1. XF\App->{closure}()
  2. call_user_func() in src/XF/FsMounts.php at line 17
  3. XF\FsMounts::loadDefaultMounts() in src/XF/App.php at line 1030
  4. XF\App->XF\{closure}() in src/XF/Container.php at line 28
  5. XF\Container->offsetGet() in src/XF/App.php at line 2410
  6. XF\App->fs() in src/XF/Util/File.php at line 193
  7. XF\Util\File::writeToAbstractedPath() in src/XF/Service/Template/Compile.php at line 146
  8. XF\Service\Template\Compile->writeCompiled() in src/XF/Service/Template/Compile.php at line 43
  9. XF\Service\Template\Compile->recompile() in src/XF/Entity/Template.php at line 433
  10. XF\Entity\Template->_postSave() in src/XF/Mvc/Entity/Entity.php at line 1208
  11. XF\Mvc\Entity\Entity->save() in src/XF/Service/Advertising/Writer.php at line 87
  12. XF\Service\Advertising\Writer->write() in src/XF/Repository/Advertising.php at line 70
  13. XF\Repository\Advertising->writeAdsTemplate() in src/XF/AddOn/DataType/AdvertisingPosition.php at line 100
  14. XF\AddOn\DataType\AdvertisingPosition->XF\AddOn\DataType\{closure}() in src/XF.php at line 290
  15. XF::triggerRunOnce() in src/XF/Mvc/Dispatcher.php at line 143
  16. XF\Mvc\Dispatcher->dispatchLoop() in src/XF/Mvc/Dispatcher.php at line 50
  17. XF\Mvc\Dispatcher->run() in src/XF/App.php at line 2178
  18. XF\App->run() in src/XF.php at line 390
  19. XF::runApp() in admin.php at line 13

Just trying this out and can confirm this happens every time addon is enabled with an updated config.php. Funnily enough can rebuild and disable it just fine. XF 2.1.11 here.
 
While it appears to have happened to a couple of users thus far, it’s not something that appears to be widespread and not something that is happening in my testing.

You need to make sure you have the correct version of the add-on installed. Especially if you previously had the add-on in XF 2.0.

The correct version of the add-on is 2.1.0 and you need to ensure you download only the XFAws-2.1.0.zip file which is available when you click Download on the resource.
 
While it appears to have happened to a couple of users thus far, it’s not something that appears to be widespread and not something that is happening in my testing.

You need to make sure you have the correct version of the add-on installed. Especially if you previously had the add-on in XF 2.0.

The correct version of the add-on is 2.1.0 and you need to ensure you download only the XFAws-2.1.0.zip file which is available when you click Download on the resource.

Correct Chris. I have the 2.1 version and never had it prior. Addon does appear to work but I can recreate this error on 2 separate VMs hosting the same forum (preprod and prod).

I actually had the same error appear first when disabling the addon but now seems to show only when re-enabling. I've uploaded addon files many times over just in case something got missed.
 
Correct Chris. I have the 2.1 version and never had it prior. Addon does appear to work but I can recreate this error on 2 separate VMs hosting the same forum (preprod and prod).

I actually had the same error appear first when disabling the addon but now seems to show only when re-enabling. I've uploaded addon files many times over just in case something got missed.
So what are the reproduction steps Chris can try out starting from no addon at all?
 
I had this same issue pop up when i upgraded to 2.2

I disabled all plugins, but left config.php file info in and triggered the error.

Make sure you are turning off both items.
 
Last edited:
So what are the reproduction steps Chris can try out starting from no addon at all?

I'm not sure, for me it's consistently reproducible.

I uploaded the addon, changed config.php, restarted php-fpm/nginx, enabled the addon, got error. Then (re)enabling it seems to always show this error without restarts of the php/web services.

I suspect it's the config.php getting cached or some other validation scenario.
 
It is possible to add a bit of protection in here to prevent the errors that you've seen but the primary reason we haven't recommended that is that what I'm about to suggest basically swallows any errors and falls back to local file storage by default.

Assuming you have something like this right now:

PHP:
$s3 = function()
{
   return new \Aws\S3\S3Client([
      'credentials' => [
         'key' => 'ABC',
         'secret' => '123'
      ],
      'region' => 'ams3',
      'version' => 'latest',
      'endpoint' => 'https://ams3.digitaloceanspaces.com'
   ]);
};

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

$config['externalDataUrl'] = function($externalPath, $canonical)
{
   return 'https://xftest.ams3.digitaloceanspaces.com/data/' . $externalPath;
};

The idea would be to wrap it in a conditional that checks whether the required classes exist first. If the classes do not exist (maybe because the add-on is disabled or not installed properly) then local file storage will be used instead. That would look something like this:

PHP:
if (class_exists('Aws\S3\S3Client')
   && class_exists('League\Flysystem\AwsS3v3\AwsS3Adapter')
)
{
   $s3 = function()
   {
      return new \Aws\S3\S3Client([
         'credentials' => [
            'key' => 'ABC',
            'secret' => '123'
         ],
         'region' => 'ams3',
         'version' => 'latest',
         'endpoint' => 'https://ams3.digitaloceanspaces.com'
      ]);
   };
   
   $config['fsAdapters']['data'] = function() use($s3)
   {
      return new \League\Flysystem\AwsS3v3\AwsS3Adapter($s3(), 'xftest', 'data');
   };
   
   $config['externalDataUrl'] = function($externalPath, $canonical)
   {
      return 'https://xftest.ams3.digitaloceanspaces.com/data/' . $externalPath;
   };
}

Note: There's no particular reason to disable add-ons routinely - particularly if you're upgrading XF. We've never said that disabling add-ons is a recommended step.

If you do have a particular reason to disable this add-on then you should comment out or remove the config entries beforehand.
 
Note: There's no particular reason to disable add-ons routinely - particularly if you're upgrading XF. We've never said that disabling add-ons is a recommended step.

If you do have a particular reason to disable this add-on then you should comment out or remove the config entries beforehand.

yeah, i was coming from 1.5 so i figured all the addons were not compatible, so i turned everything off before running the upgrade process.

It was an easy fix, though a slight hiccup in the /install process.
 
What if I want to store attachment only (images and videos only), the rest serve from default xenforo, is it possible to do? Could you help me @Chris D
I'm using Digitalocean
 
Top Bottom