dcasia/nova-filepond

Error during load

Opened this issue · 3 comments

Awesome package.

Just one error when i try to keep my filename and store to my media disk.

        Filepond::make('Movie', 'movie')
            ->store(function (Request $request, $model) {
                $filename = $request->movie->getClientOriginalName();
                $request->movie->storeAs('movie', $filename, 'media');
                return [
                    'movie' => 'movie/' . $filename,
                ];
            })
            ->columns(4)
            ->disableCredits()
            ->limit(20)
            ->multiple()
            ->prunable(),

And what is the error?

you can follow this example:

use DigitalCreative\Filepond\Filepond;

class Post extends Resource
{
    public function fields(NovaRequest $request): array
    {
        return [
            Filepond::make('Images', 'images')
                ->storeOriginalName('name')
                ->storeSize('size')
                ->multiple(),
            
            // or you can manually decide how to store the data
            // Note: the store method will be called for each file uploaded and the output will be stored into a single json column
            Filepond::make('Images', 'images')
                ->multiple()
                ->store(function (NovaRequest $request, Model $model, string $attribute): array {
                    return [
                        $attribute => $request->images->store('/', 's3'),
                        'name' => $request->images->getClientOriginalName(),
                        'size' => $request->images->getSize(),
                        'metadata' => '...'
                    ];
                })
        ];
    }
}

Storing metadata in your documentation works perfectly.
The problem is when you wish to keep the original file name in your upload folder.
When I use the storeAs method in the Nova documentation, I have this error:

image

I use this method when I wish to keep the original name of my uploaded files and when I wish to create a custom path :

Image::make('Image', 'image')
->disk('public')
->path('media/image')
->storeAs(function (Request $request) {
return $request->image->getClientOriginalName();
})
->nullable()
->prunable()
->sortable(),

With this method available in the Nova documentation, I use the public disk and create a custom path media/image and the upload of my file will keep the original name, for example angel.jpg.

Now when I use Filepond, the original file name is perfectly preserved in my upload folder and the custom path is created too:

Filepond::make('Image', 'image')
->disk('public')
->path('media/image')
->storeAs(function (Request $request) {
return $request->image->getClientOriginalName();
})
->prunable()
->multiple(),

But the error appears in view mode and edit mode and it is impossible to preview the uploaded file:

image

If I check the image column in my database:
["media\/image\/angel.jpg"]

When I edit the syntax in the path, it doesn't change anything:
["media/image/angel.jpg"]

The error message doesn't display the original name of the image angel.jpg but it displays:
eyJpdiI6IjNUYXpvbnF5VkJ0QmE0dlltbkNNTHc9PSIsInZhbHVlIjoiMWE2WDV6Um9SZnhQczZDN1JhZkg3a3lJZzhxa1d2MXlMZExVc3Yrdk9zTnJHOEttcnl5Tnp2OXdSNCttUkpQY2NyallrY2xhaHJUL1lXdTdpVXQ2N0s3cGZ0ZXJOZGIxcEhGQ2JrQkVaU3k0ZnE2dzBLckcxRHVyeGZGVzlMd2FkNk5DdDgwZDFlT3UzSkh0ZVkrRHVFWTBEV21ZK3RFZHNtbFhsTlVORGxlNU1VZk00ZVBuVEpEZklQMXZQVWFMUUExbEdzcGNEbUR3ckhyVXRNekR0QT09IiwibWFjIjoiYzM3YjRkOGViNDRkYWU3MjYxNTQ3NzMzMjk1MGZhYTk5NjdkNjdmNDkxOTkxYzZlYWQ2N2E0NzJlZDllYjZiYyIsInRhZyI6IiJ9

The error appears during load.

Having the same problem, it seems the last commit f27930e is causing this issue and removing the change done fix the issue.
I experienced this when the pictures were set to show a preview.
@milewski The issue is that once a path is set and contains "/" the issue occurs. To fix it you should do urlencode($data->filename). I submitted a pull request for it