varundavda's avatar

Store images on cloud with intervention

Hello all,

I am uploading an image on local using intervention and everything is working fine.

Now i want to store images on cloud. I am able to store images on cloud without using intervention.

But i want to use intervention and then upload images to cloud.

I am using this code which does stores the image on cloud but it stores as empty images of 0kb.

public function storeImage(Request $request)
    {

        $file = $request->file('image_name');

        $extension = $file->getClientOriginalExtension();

        $fileName = rand(11111, 99999) . '.' . $extension;
        
        // $destinationPath = 'testing';
    
        $image = \Image::make($file);

        // Storage::put($fileName,  File::get($file));
    //the above code works and stores images on cloud. This is without using intervention.
 
        Storage::put($fileName , $image);
    //this stores the image but a blank file. (0KB file size)

        // Storage::put('home/'.$fileName , $image); 

        // $image->save($destinationPath.'/'.$fileName);

        // $status =  Storage::put('home/'.$fileName , $image);
        
        // dd($status);

    }

How can i make image in intervention and then store it on cloud?

0 likes
6 replies
johnny's avatar

You may use the Storage class to store them on your cloud server:

Something like this should work fine:

Storage::disk('s3')->put($filename, (string) $image);
johnny's avatar

Do you still get an empty file as the result?

johnny's avatar
johnny
Best Answer
Level 6

Could you try this? It's working fine for me:

$image->encode('jpg'); 

Storage::disk('s3')->put($filename, (string) $image);

Update: I just did a test with the S3 disk and it's working fine as I mentioned above.

1 like

Please or to participate in this conversation.