0

It's almost 48 hours that I'm facing an issue with the files upload to Digital Ocean spaces from laravel and I can't make it work.

I've successfully built a livewire component that handle the multiple upload of images, each image is stored in the laravel local storage.

As on this website we plan to host thousands of different images, we have now decided to use Digital Ocean Spaces as storage disk.

In order to do so, as first I installed league/flysystem-aws-s3-v3 composer package as required.

Than in my config/filesystem.phpI've done the following :

'do_spaces' => [     
            'driver' => 's3',     
            'key' => env('DO_SPACES_KEY'),     
            'secret' => env('DO_SPACES_SECRET'),     
            'endpoint' => env('DO_SPACES_ENDPOINT'),     
            'region' => env('DO_SPACES_REGION'),     
            'bucket' => env('DO_SPACES_BUCKET'), 
        ],

And in my .env the following :

DO_SPACES_KEY=key
DO_SPACES_SECRET=secret
DO_SPACES_ENDPOINT=https://ams3.digitaloceanspaces.com
DO_SPACES_REGION=AMS3 
DO_SPACES_BUCKET=bucket_name

In my livewire component, after uploading the image to local storage, for each image I'm dispatching a job(dispatch(new ResizeUploadToDo($pic, $extension));) which is supposed to :

  • Retrieve the image from local storage
  • Pass it to Intervention library in order to resize it and apply a watermark.
  • Upload the manipulated Image to Digital Ocean Spaces
  • Remove the old image from local storage

This is the code I've written so far in my job handle() method :

public function handle()
    {   
        $path = Storage::disk('local')->path($this->pic->storage_file_path);
        $img=Image::make($path);
        $img->resize(600, 600);
        $folderStructure = Carbon::now()->format('Y') . '/' . Carbon::now()->format('m') . '/' . Carbon::now()->format('d'). '/';
        $filename=time().'.'.$this->extension;

        Storage::disk('do_spaces')->put($folderStructure . $filename, $img, 'public');

        
    }

The issues that I'm now facing are the following :

  1. If i try to dd($img) right after instanciate it with Intervention library, i get the following :
     Intervention\Image\Image {#1570 ▼ // app\Jobs\Images\ResizeUploadToDo.php:49
          #driver: Intervention\Image\Gd\Driver {#1578 ▼
            +decoder: Intervention\Image\Gd\Decoder {#1598 ▼
              -data: null
            }
            +encoder: Intervention\Image\Gd\Encoder {#363 ▼
              +result: null
              +image: null
              +format: null
              +quality: null
            }
          }
          #core: GdImage {#394 ▼
            +size: "600x600"
            +trueColor: true
          }
          #backups: []
          +encoded: ""
          +mime: "image/png"
          +dirname: "C:\Users\Gianmarco\wa\hotelista\storage\app22/12/12"
          +basename: "SPcNL5FD3OZV4heHWA103J4n5YU8xOCG1SU7pyMd.png"
          +extension: "png"
          +filename: "SPcNL5FD3OZV4heHWA103J4n5YU8xOCG1SU7pyMd"
        }

To me it seems like the retrieved Image is empty, is it correct? Or how should i do to correctly retrieve the image from local storage?

  1. I've noticed that, If the job runs with queue driver sync, files get uploaded to Digital Ocean Spaces but they are empty (file size: 0MB); while, if the job runs with queue driver 'database' files are not uploaded at all to Digital Ocean Spaces.

Doea anybody know how to solve this matter?

Hope somebody can help me with it. Thank you

Gianmarco
  • 69
  • 1
  • 9

1 Answers1

0
  1. Add this variable 'url' => env('DO_SPACES_URL') below 'bucket' => env('DO_SPACES_BUCKET'), in filesystems.php.

  2. In your .env put the variable DO_SPACES_URL=https://{your bucket name}.ams3.digitaloceanspaces.com

  3. Upload file like this:

Storage::disk('do_spaces')->put('uploads', $request->file('file'), 'public');
SEYED BABAK ASHRAFI
  • 4,093
  • 4
  • 22
  • 32
Mike
  • 1