F
Filament14mo ago
MRBUG

Download button for file's Inside Repeater.

how can we download the any type of file that is coming from s3. More details: Here is the model which i am using inside Repeater
MessageFile modal
protected $appends = [
'file_url',
];
public function getFileUrlAttribute()
{
if (config('filesystems.default') == 's3') {
return Storage::disk(config('filesystems.default'))->temporaryUrl('messages/' . $this->message_id . '/' . $this->hashname, now()->addMinutes(5));
} else {
return Storage::url('messages/' . $this->message_id . '/' . $this->hashname);
}
}
MessageFile modal
protected $appends = [
'file_url',
];
public function getFileUrlAttribute()
{
if (config('filesystems.default') == 's3') {
return Storage::disk(config('filesystems.default'))->temporaryUrl('messages/' . $this->message_id . '/' . $this->hashname, now()->addMinutes(5));
} else {
return Storage::url('messages/' . $this->message_id . '/' . $this->hashname);
}
}
i am using Action inside the MessageResource Like that
and i am getting the url but it it's saying file does'not exist and i this this approach is not good? ``` ->actions([ //other codes ->infolist([ RepeatableEntry::make('message.messageFiles') ->schema([ ImageEntry::make('fileurl')->height(80), TextEntry::make('size') ->suffixAction( Action::make('download') ->action(function (MessageFile $record, array $data) { if ($record->fileurl) { $dd = response()->download(storage_path($record->fileurl)); } else { Log::error('File not found: ' . $record->fileurl); Notification::make() ->title('File Not Found') ->danger() ->send();
Solution:
I use that exact method perfectly fine. If you are calling storage_path() then you should only be retuning for example" messageFiles/myfile.zip...
Jump to solution
6 Replies
toeknee
toeknee14mo ago
Are you sure the file exists? if you dd the file path is it 100% right
MRBUG
MRBUGOP14mo ago
yes it exists but i think i am getting wrong location there
return response()->download(storage_path($record->fileurl));
return response()->download(storage_path($record->fileurl));
and the modal is above. @toeknee it think the problem is this i am getting this
/home/devisop/htdocs/filamentproject/storage/https://filamentproject-testing.s3
/home/devisop/htdocs/filamentproject/storage/https://filamentproject-testing.s3
before my actual url. i think this should be start from here ?
`https://filamentproject-testing.s3
`https://filamentproject-testing.s3
toeknee
toeknee14mo ago
That’s because you are loading in the storage path with a url… you shouldn’t store the url but the storage path
MRBUG
MRBUGOP14mo ago
ok @toeknee i am getting the exact location and it's exists but i think this it is the problem of my method of dowloading the file ? sir any suggetions to implement download button.
Solution
toeknee
toeknee14mo ago
I use that exact method perfectly fine. If you are calling storage_path() then you should only be retuning for example" messageFiles/myfile.zip as storage path builds: /home/devisop/htdocs/filamentproject/storage/
MRBUG
MRBUGOP14mo ago
ok.
Want results from more Discord servers?
Add your server