freescout icon indicating copy to clipboard operation
freescout copied to clipboard

Filesystem with Digital Ocean spaces or S3

Open rapsli opened this issue 3 years ago • 4 comments

Unfortunately the documentation here is not very clear. First of all it will not work with PHP > 8 So I have downgraded to PHP 7.4.

Installing the required package:

composer require league/flysystem-aws-s3-v3 ~1.0

I haved added the S3 and DO credentials to the .envfile for either S3 or DO spaces. It was never running. It was sometimes uploading vars.js to either S3 or DO, but that was about it. I could never get it to upload the actual attachments.

What is not quite clear:

  • Are there any changes required in conf/filesystems.php? I have added a DO disk similar to the s3 disk, to test out the DO configuration, but unfortunately with no success. When changing the FILESYSTEM_DRIVER from local to s3 I get the following error:
During inheritance of Countable: Uncaught ErrorException: Return type of Aws\HandlerList::count() should either be compatible with Countable::count(): int, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice
in /home/runcloud/webapps/freescout/vendor/aws/aws-sdk-php/src/HandlerList.php:308

Do I have to remove any files from storage in order for S3 to work?

rapsli avatar Aug 22 '22 13:08 rapsli

It looks like the package you are using is not compatible with PHP 8.1

freescout-helpdesk avatar Aug 22 '22 13:08 freescout-helpdesk

yes I agree, that's why I have downgraded to PHP 7.4... but even so it's not working

rapsli avatar Aug 22 '22 13:08 rapsli

A quick update. I can now upload files again: the URL points to the file on AWS, but the file is actually uploaded to the local storage (/storage/app/attachment) and nothing arrives at AWS. Clicking on the file will lead to a broken link.

image

rapsli avatar Aug 22 '22 14:08 rapsli

We've never tried this ourselves. We'll leave this issue as help wanted. Maybe someone will help.

freescout-helpdesk avatar Sep 02 '22 08:09 freescout-helpdesk

any news here? Just tried to setup another instance... not having to worry about storage for attachments would make life a lot easier!

rapsli avatar Jan 16 '23 19:01 rapsli

Got it running. Here is what I had to change. This is now obviously hardcoded I would assume, it will need some more love, but I'm not familiar at all with Laravel, so hopefully someone smarter than me with a more oversights can get this into a generic form.


diff --git a/app/Attachment.php b/app/Attachment.php
index 2fc5d687..5a555341 100644
--- a/app/Attachment.php
+++ b/app/Attachment.php
@@ -19,7 +19,7 @@ class Attachment extends Model

     const DIRECTORY = 'attachment';

-    CONST DISK = 'private';
+    CONST DISK = 's3';

     // https://github.com/Webklex/laravel-imap/blob/master/src/IMAP/Attachment.php
     public static $types = [
@@ -231,7 +231,9 @@ class Attachment extends Model
      */
     public function url()
     {
-        return Storage::url($this->getStorageFilePath()).'?id='.$this->id.'&token='.$this->getToken();
+
+       return Storage::disk('s3')->temporaryUrl($this->getStorageFilePath(), now()->addMinutes(30));
+        //return Storage::url($this->getStorageFilePath()).'?id='.$this->id.'&token='.$this->getToken();
     }

rapsli avatar Jan 17 '23 15:01 rapsli

Thanks for sharing the solution.

freescout-helpdesk avatar Feb 14 '23 10:02 freescout-helpdesk