Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error during load #46

Open
AppDevXXX opened this issue Jan 5, 2024 · 3 comments
Open

Error during load #46

AppDevXXX opened this issue Jan 5, 2024 · 3 comments

Comments

@AppDevXXX
Copy link

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(),
@milewski
Copy link
Member

milewski commented Jan 6, 2024

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' => '...'
                    ];
                })
        ];
    }
}

@AppDevXXX
Copy link
Author

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.

@AppDevXXX AppDevXXX changed the title Error during load with store and filename Error during load Jan 13, 2024
@aem-coding
Copy link
Contributor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants