S3 Storage and file path for signed key

I am setting up Twill stored files with signed keys from AWS. Normally I would be calling the filename like so:
$file_model->file('file_name')
$file_model->file('file_name')
And this gets the whole src URL for amazon domain + directory + filename. I am doing this to overcome the full S3 path being returned from model and generate signed url aswell:
$twill_file_id = \DB::table('twill_fileables')->where('fileable_id', $lesson_id)->value('file_id');
$twill_file_uuid = \DB::table('twill_files')->where('id', $twill_file_id)->value('uuid');

$temporarySignedUrl = \Storage::disk('s3')->temporaryUrl($twill_file_uuid, now()->addMinutes(10));
$twill_file_id = \DB::table('twill_fileables')->where('fileable_id', $lesson_id)->value('file_id');
$twill_file_uuid = \DB::table('twill_files')->where('id', $twill_file_id)->value('uuid');

$temporarySignedUrl = \Storage::disk('s3')->temporaryUrl($twill_file_uuid, now()->addMinutes(10));
Is there a better option that generates the temporary signed url in Twill out of the box? Or atleast a cleaner way to call the URL by only the directory structure not the whole URL with amazon.com base without having to query the two tables?
1 Reply
ifox
ifox7mo ago
Hi @devtutorum just seeing this, sorry. a better option would be to implement a service, like we do for image rendering. With a service class you'd still be able to use ->file() on your models. in the service you would directly get the file UUID.