Merge pull request #15309 from angus-mcritchie/add-max-parallel-file-uploads-option

feat/bug-fix: add maxParallelUploads option to FileUpload component
This commit is contained in:
Dan Harrin
2025-01-10 12:04:47 +00:00
committed by GitHub
5 changed files with 38 additions and 7 deletions
File diff suppressed because one or more lines are too long
@@ -70,6 +70,20 @@ class Message extends Model
}
```
### Controlling the maximum parallel uploads
You can control the maximum number of parallel uploads using the `maxParallelUploads()` method:
```php
use Filament\Forms\Components\FileUpload;
FileUpload::make('attachments')
->multiple()
->maxParallelUploads(1)
```
This will limit the number of parallel uploads to `1`. If unset, we'll use the [default FilePond value](https://pqina.nl/filepond/docs/api/instance/properties/#core-properties) which is `2`.
## Controlling file names
By default, a random file name will be generated for newly-uploaded files. This is to ensure that there are never any conflicts with existing files.
@@ -57,6 +57,7 @@ export default function fileUploadFormComponent({
maxFiles,
maxSize,
minSize,
maxParallelUploads,
panelAspectRatio,
panelLayout,
placeholder,
@@ -122,6 +123,7 @@ export default function fileUploadFormComponent({
maxFiles,
maxFileSize: maxSize,
minFileSize: minSize,
...(maxParallelUploads && { maxParallelUploads }),
styleButtonProcessItemPosition: uploadButtonPosition,
styleButtonRemoveItemPosition: removeUploadedFileButtonPosition,
styleItemPanelAspectRatio: itemPanelAspectRatio,
@@ -71,6 +71,7 @@
maxFiles: @js($getMaxFiles()),
maxSize: @js(($size = $getMaxSize()) ? "{$size}KB" : null),
minSize: @js(($size = $getMinSize()) ? "{$size}KB" : null),
maxParallelUploads: @js($getMaxParallelUploads()),
removeUploadedFileUsing: async (fileKey) => {
return await $wire.removeFormUploadedFile(@js($statePath), fileKey)
},
@@ -46,6 +46,8 @@ class BaseFileUpload extends Field implements Contracts\HasNestedRecursiveValida
protected int | Closure | null $minSize = null;
protected int | Closure | null $maxParallelUploads = null;
protected int | Closure | null $maxFiles = null;
protected int | Closure | null $minFiles = null;
@@ -393,6 +395,13 @@ class BaseFileUpload extends Field implements Contracts\HasNestedRecursiveValida
return $this;
}
public function maxParallelUploads(int | Closure | null $count): static
{
$this->maxParallelUploads = $count;
return $this;
}
public function maxFiles(int | Closure | null $count): static
{
$this->maxFiles = $count;
@@ -540,6 +549,11 @@ class BaseFileUpload extends Field implements Contracts\HasNestedRecursiveValida
return $this->evaluate($this->minSize);
}
public function getMaxParallelUploads(): ?int
{
return $this->evaluate($this->maxParallelUploads);
}
public function getVisibility(): string
{
return $this->evaluate($this->visibility);