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

kylehudson's avatar

Spark Profile pics S3

Hello,

Is it possible to save the profile images in Spark to S3 or other cloud storage. Due to the way our servers are setup we cannot create the symlinks required.

Thanks in advance.

0 likes
5 replies
haydenp's avatar

This worked for me ... (must add AWS settings to the filesystems config)

    public function booted()
    {
        // Override the default UpdateProfilePhoto@handle method which stores the file locally
        Spark::swap('UpdateProfilePhoto@handle', function ($user, array $data)
        {
            $imageManager = new ImageManager();

            $file = $data['photo'];
            $formatImage = (string) $imageManager->make($file->path())->fit(300)->encode();

            $path = $file->hashName('profiles');

            // Store the file on s3, grab the url and store with this user in the database row.
            $disk = Storage::disk('s3');

            $disk->put(
                $path, $formatImage
            );

            $user->forceFill([
                'photo_url' => $disk->url($path),
            ])->save();
        });
    }
3 likes
bryanmonzon's avatar

@haydenp Did you add this to SparkServiceProvider.php? Where did you import the ImagManager from? Thanks!

haydenp's avatar

@bryan yes, thats the booted() method inside my SparkServiceProvider.php. And ImageManager ...

use Intervention\Image\ImageManager;
use Illuminate\Support\Facades\Storage;

Hope that answers your question ;-)

1 like
richard@gorbutt.com's avatar

So, I looked at this and found it a lot simpler to change the 'public' in the config/filesystem.php to

 'public' => [
            'driver' => 's3',
            'key' => env('AWS_KEY'),
            'secret' => env('AWS_SECRET'),
            'region' => env('AWS_REGION'),
            'bucket' => env('AWS_BUCKET'),
        ],

Not aware of any other impact.

Took a little tweaking on the S3 side to make the profiles folder public etc.

Please or to participate in this conversation.