dcasia / nova-filepond

A Nova field for uploading File, Image and Video using Filepond.
MIT License
49 stars 28 forks source link

Download and view file on Edit page #14

Open vayurobins opened 4 years ago

vayurobins commented 4 years ago

Hi. Is it possible to have a download link to the uploaded file after it has been saved to the database/S3?

milewski commented 4 years ago

Hi perhaps this is supported by installing this plugin: https://github.com/nielsboogaard/filepond-plugin-get-file, can you have a try if it works I can incorporate into this field

royduin commented 4 years ago

Another approach could be to only show this field on forms with ->onlyOnForms() and then create a "fake" text field where you can do whatever you want, for example:

Text::make('Attachments', function () {
    $html = '';
    foreach ($this->attachments ?? [] as $attachment) {
        $html .= '<li><a href="'.$attachment.'">'.$attachment.'</a></li>';
    }
    return $html ? '<ul>'.$html.'</ul>' : null;
})->asHtml()->onlyOnDetail(),
Shehan-Sara commented 3 months ago

@royduin I modified your code a bit. Hopefully, this works for me.

Text::make('documents', function () {
                $appUrl = Config::get('app.url'); // Fetch the APP_URL from the configuration
                $html = '';
                foreach ($this->documents ?? [] as $document) {
                    $html .= '<li><a href="' . $appUrl . '/storage/' . $document . '" target="_blank">' . $appUrl . '/storage/' . $document . '</a></li>';
                }
                return $html ? '<ul>' . $html . '</ul>' : null;
            })->asHtml()->onlyOnDetail(),