Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Givar's avatar
Level 1

Issue with retrieving image in job

Hello Everybody,

I've succesfully built a livewire component which upload multiple images to local storage. Now, I would like to move the uploaded files from the local storage to Digital Ocean Spaces and i thought to do so :

  1. The livewire component uploads the image to the local file storage and saves the local path to the DB.
  2. Once the upload is done i would like to dispatch a job where i will retrieve the file from local storage, process it with ImageIntervention(resize, add watermark) and then upload the processed file to DO SPACES.
  3. Once the upload to Do_SPACES is succesfull, remove the file from the local_storage.

Now I'm facing issue in retrieving the image from local storage inside the job.

To retrieve the image inside the job I'm doing :

$img=Storage::get(local_storage_path)

But when i try to dd($img) i get :

Ï Ó\x00\x10JFIF\x00\x01\x01\x01\x01,\x01,\x00\x00 █\x00C\x00\x02\x01\x01\x02\x01\x01\x02\x02\x02\x02\x02\x02\x02\x02\x03\x05\x03\x03\x03\x03\x03\x06\x04\x04\x03\x05\x07\x06\x07\x07\x07\x06\x07\x07\x08\t\v\t\x08\x08\x08\x07\x07\v\f\f\f\f\x07\t\x0E\x0F\f\x0E\v\f\f\f █\x00C\x01\x02\x02\x02\x03\x03\x03\x06\x03\x03\x06\f\x08\x07\x08\f\f\f\f\f\f\f\f\f\f\f\f\f\f\f\f\f\f\f\f\f\f\f\f\f\f\f\f\f\f\f\f\f\f\f\f\f\f\f\f\f\f\f\f\f\f\f\f\f\f └\x00\x11\x08\t\x1E¼\x03\x01"\x00\x02\x11\x01\x03\x11\x01 ─\x00\x1E\x00\x01\x00\x00\x06\x03\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x04\x05\x06\x07\x08\t\x01\x02\x03 ─\x00o\x10\x00\x01\x03\x02\x03\x04\x04\x05\v\v\x0F\v\x02\x03\x02\x0F\x00\x01\x02\x03\x04\x05\x06\x07\x11\x08\x12!1\x13AQa\t"qüæ\x14\x152BRVôí▒Ð\x16\x17\x18#SUbrÆ┴Ê\x19346CTsuéöò▓│Ëß\x1A$578WctvûóÁ­%9Dâ┤┬údä±&'eÈ(Ef├ÔÒ ─\x00\x1D\x01\x01\x00\x01\x04\x03\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x06\x03\x04

a lot of characters.

My question is, how do i correctly retrieve the image from local storage in order to process it in the job? Hope somebody can help me.

Thank you.

0 likes
16 replies
Sinnbeck's avatar

Just copy it from one to the other. Assuming the Digital ocean disk is named "do"

Storage::disk('do')->put(
  $filename,
  Storage::disk('local')->get($localPath)
);
2 likes
Givar's avatar
Level 1

@Sinnbeck thank you for your quick reply.

Just to make sure, what's inside the $filename that you pass to the put() method? Also, by doing so, how can i manipulate the img with ImageIntervention before uploading to DO_SPACES? Thank you

1 like
Sinnbeck's avatar

@Givar Whatever name it should get on digital ocean. Maybe the original filename or part of $localPath? As I dont know your variables and file names, i can only guess

2 likes
Givar's avatar
Level 1

@Sinnbeck Thank you so much.

What about manipulating the image before uploading to do_spaces? Thank you

Givar's avatar
Level 1

@Sinnbeck yes, this is what i was planning to use. Thank you.

I meant how can i retrieve the image from Local storage and pass it to Image::make(). The same way as for do?

Thanks

Sinnbeck's avatar

@Givar You can pass it using the path

$path = Storage::disk('local')->path($localPath);
$image = Image::make($path);
1 like
Givar's avatar
Level 1

@Sinnbeck Thank you. I got it to work with your suggestions.

Now I'm facing issues with Storage::disk('do_spaces') as the job executes the line correctly without throwing any error but files are not uploaded to digital_ocean.

Givar's avatar
Level 1

@Sinnbeck you are so helpful. Thank you so much.

As first I've installed league/flysystem-aws-s3-v3 package as required.

Then in my config/filesystems.php I've added 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 I've done :

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

And it should be everything to get it work.

In my job I'm doing :

$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);

This code throws no errors at all but at the end the files are not uploaded to DO_spaces.

Sinnbeck's avatar

@Givar ok first make sure it's actually being run. Set the queue driver to sync and add a dd('hit'); in the code. Does it trigger?

Givar's avatar
Level 1

@Sinnbeck it triggers the same and prints the following :


"2022/12/12/1670861352.png" // app\Jobs\Images\ResizeUploadToDo.php:49
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"
}

Givar's avatar
Level 1

@Sinnbeck I have now noticed that when using queue driver set to 'sync' it actually upload files on DO but if I try to open the URL given from DO this is what i get :

This XML file does not appear to have any style information associated with it. The document tree is shown below.
<Error>
<Code>AccessDenied</Code>
<BucketName>hotelista</BucketName>
<RequestId>tx0000000000000bc2f237a-00639753d9-2914ac4a-ams3c</RequestId>
<HostId>2914ac4a-ams3c-ams3-zg03</HostId>
</Error>

While, when using queue driver set to 'database' it doesn't upload the file to DO.

azbx's avatar

the $filename variable is the name of the imported image.

1 like

Please or to participate in this conversation.