Published 1 week ago by joshuaf
So, I have my own code to upload a profile image to an s3 bucket, but I also want it to work for the settings/profile page. I would think that this would be easy as this is something that most people have to do, but I don't see an easy solution or anything in the docs about it.
Altering the photo controller is not really realistic as I deploy with composer. It is possible to alter the updaet function in update-profile-photo.js asset to point to a different URL, and then rebuild the assets, but this seems wrong.
I tried simply adding a route to direct the /settings/photo post call to my own function, but that never worked for some reason.
Laravel stores profile images in the "public" disk as default. You'd just have to set the "public" disk to use S3 in /config/filesystems.php.
'public' => [ 'driver' => 's3', 'key' => env('AWS_KEY'), 'secret' => env('AWS_SECRET'), 'region' => env('AWS_REGION'), 'bucket' => env('AWS_BUCKET'), ]
And set the AWS_KEY, etc., in your .env with your credentials/settings and include/install
league/flysystem-aws-s3-v3 ~1.0 in composer
It would have been nice if they allowed you to set which disk Spark uses for profile images in .env. Maybe I'll do a PR for that, but I'm not using Spark v6 so they probably wouldn't add it in. It will take days to upgrade so I've been avoiding it, and there's nothing really functionally different between v5 and v6 except for using bootstrap4 in v6 vs bs3 in v5 (and below) so it hasn't been a high priority.
Thanks. Worked like a charm. Any recommendation as to how I can force the naming convention? I want to assign specific names instead of the random string.
Also, I want to direct team images into a separate folder. I don't see how I can do that without altering the spark code though.
Any recommendation as to how I can force the naming convention? I want to assign specific names instead of the random string.
You'd have to edit the storage method like I was showing from yesterday. I haven't tried to mess with it but this is where you'd do it. The pertinent lines are
// this is setting the filename $path = $file->hashName('profiles'); $disk = Storage::disk('public'); // you'd want to change this to ->putFileAs() and specify the name $disk->put( $path, $this->formatImage($file) );
I thought that was the case, but since I have a database entry for each team and user and user and those entries have a unique ID associated with them ... my thinking was that I would have a folder for "profile" images and a folder for "team" images and the name of each would simply be the ID number. That way, if there was every any database issue, I would know which image went with which user/team via the name.