© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
FilamentF
Filament•3y ago•
17 replies
eazy

Spatie Media Library File Upload replacing every uploaded file

Hello, I have created a custom action for a file upload to my table, but when I upload a file it replaces all the already uploaded files. This hasn't been happening before.
After going through the code I found out the
deleteAbandonedFiles()
deleteAbandonedFiles()
method in the plugin, this gets called in the
saveRelationshipUsing()
saveRelationshipUsing()
method. It looks to me that only the uploaded file UUID gets added to the state so the rest of the files get deleted. But I'm not sure how to fix this.

My custom action:
    protected function setUp(): void
    {
        parent::setUp();

//        $this->authorize('upload-file');

        $this->label(__('filemanager.upload file'));

        $this->modalButton(__('filemanager.upload file'));

        $this->modalHeading(__('filemanager.upload file'));

        $this->button();

        $this->successNotificationTitle(__('filemanager.file uploaded'));

        $this->icon('tabler-file-upload');

        $this->form(function () {
            $field = SpatieMediaLibraryFileUpload::make('file')
                ->model($this->record)
                ->disableLabel()
                ->required()
                ->multiple()
                ->minFiles(1)
                ->maxSize(500_000); // 500mb

            $acceptedFileTypes = $this->getAcceptedFileTypes();

            if (!empty($acceptedFileTypes) && $acceptedFileTypes !== null) {
                $field->acceptedFileTypes($acceptedFileTypes);
            }

            return [$field];
        });

        $this->action(fn(UploadFilesAction $action) => $action->success());
    }
    protected function setUp(): void
    {
        parent::setUp();

//        $this->authorize('upload-file');

        $this->label(__('filemanager.upload file'));

        $this->modalButton(__('filemanager.upload file'));

        $this->modalHeading(__('filemanager.upload file'));

        $this->button();

        $this->successNotificationTitle(__('filemanager.file uploaded'));

        $this->icon('tabler-file-upload');

        $this->form(function () {
            $field = SpatieMediaLibraryFileUpload::make('file')
                ->model($this->record)
                ->disableLabel()
                ->required()
                ->multiple()
                ->minFiles(1)
                ->maxSize(500_000); // 500mb

            $acceptedFileTypes = $this->getAcceptedFileTypes();

            if (!empty($acceptedFileTypes) && $acceptedFileTypes !== null) {
                $field->acceptedFileTypes($acceptedFileTypes);
            }

            return [$field];
        });

        $this->action(fn(UploadFilesAction $action) => $action->success());
    }
Filament banner
FilamentJoin
A powerful open source UI framework for Laravel • Build and ship admin panels & apps fast with Livewire
20,307Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

spatie media library file upload load file
FilamentFFilament / ❓┊help
2y ago
Unique identifier for file upload (Spatie Media Library)? 🤷♂
FilamentFFilament / ❓┊help
2y ago
Spatie media library file name in form when uploaded
FilamentFFilament / ❓┊help
3y ago
Spatie Media File Upload Issue
FilamentFFilament / ❓┊help
2y ago