FilamentF
Filament2y ago
SJ

Upload Files automatically in FileUpload after Drag & Drop

I would like to create a simple file upload form that automatically saves the files after drag & drop or after file selection in the location specified in the code without an additional submit button.

Would this be possible with Filament Forms?

    public function form(Form $form): Form
    {
        return $form
            ->statePath('data')
            ->schema([
                FileUpload::make('file')
                ->label('Dateien hochladen')
                ->disk('s3')
                ->directory($this->path)
                ->imagePreviewHeight('150')
                ->preserveFilenames()
                ->multiple()
                ->moveFiles()
                ->removeUploadedFileButtonPosition('right')
                ->uploadButtonPosition('right')
                ->uploadProgressIndicatorPosition('left')
            ]);
    }
Solution
Okay after some digging in the Classes i found this:
->afterStateUpdated(function (FileUpload $component) {
          $component->saveUploadedFiles($component);
          $this->updateMedia();
})
Was this page helpful?