mirror of
https://github.com/filamentphp/filament.git
synced 2026-09-24 15:42:09 +08:00
Merge branch '3.x' into 4.x
This commit is contained in:
@@ -58,6 +58,7 @@ export default function fileUploadFormComponent({
|
||||
maxSize,
|
||||
minSize,
|
||||
maxParallelUploads,
|
||||
mimeTypeMap,
|
||||
panelAspectRatio,
|
||||
panelLayout,
|
||||
placeholder,
|
||||
@@ -202,9 +203,15 @@ export default function fileUploadFormComponent({
|
||||
},
|
||||
fileValidateTypeDetectType: (source, detectedType) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
const extension = source.name
|
||||
.split('.')
|
||||
.pop()
|
||||
.toLowerCase()
|
||||
const mimeType =
|
||||
mimeTypeMap[extension] ||
|
||||
detectedType ||
|
||||
mime.getType(source.name.split('.').pop())
|
||||
mime.getType(extension)
|
||||
|
||||
mimeType ? resolve(mimeType) : reject()
|
||||
})
|
||||
},
|
||||
|
||||
@@ -81,6 +81,7 @@
|
||||
maxFiles: @js($getMaxFiles()),
|
||||
maxSize: @js(($size = $getMaxSize()) ? "{$size}KB" : null),
|
||||
minSize: @js(($size = $getMinSize()) ? "{$size}KB" : null),
|
||||
mimeTypeMap: @js($getMimeTypeMap()),
|
||||
maxParallelUploads: @js($getMaxParallelUploads()),
|
||||
removeUploadedFileUsing: async (fileKey) => {
|
||||
return await $wire.callSchemaComponentMethod(
|
||||
|
||||
@@ -77,6 +77,11 @@ class FileUpload extends BaseFileUpload
|
||||
*/
|
||||
protected array | Closure $imageEditorAspectRatios = [];
|
||||
|
||||
/**
|
||||
* @var array<string, string> | Closure
|
||||
*/
|
||||
protected array | Closure $mimeTypeMap = [];
|
||||
|
||||
public function appendFiles(bool | Closure $condition = true): static
|
||||
{
|
||||
$this->shouldAppendFiles = $condition;
|
||||
@@ -629,4 +634,22 @@ class FileUpload extends BaseFileUpload
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string, string> | Closure $map
|
||||
*/
|
||||
public function mimeTypeMap(array | Closure $map): static
|
||||
{
|
||||
$this->mimeTypeMap = $map;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, string>
|
||||
*/
|
||||
public function getMimeTypeMap(): array
|
||||
{
|
||||
return $this->evaluate($this->mimeTypeMap);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -460,6 +460,24 @@ FileUpload::make('image')
|
||||
->image()
|
||||
```
|
||||
|
||||
#### Custom MIME type mapping
|
||||
|
||||
Some file formats may not be recognized correctly by the browser when uploading files. Filament allows you to manually define MIME types for specific file extensions using the `mimeTypeMap()` method:
|
||||
|
||||
```php
|
||||
use Filament\Forms\Components\FileUpload;
|
||||
|
||||
FileUpload::make('designs')
|
||||
->acceptedFileTypes([
|
||||
'x-world/x-3dmf',
|
||||
'application/vnd.sketchup.skp',
|
||||
])
|
||||
->mimeTypeMap([
|
||||
'3dm' => 'x-world/x-3dmf',
|
||||
'skp' => 'application/vnd.sketchup.skp',
|
||||
]);
|
||||
```
|
||||
|
||||
### File size validation
|
||||
|
||||
You may also restrict the size of uploaded files in kilobytes:
|
||||
|
||||
@@ -57,6 +57,8 @@ return [
|
||||
|
||||
'filters' => [
|
||||
|
||||
'heading' => 'Filteri',
|
||||
|
||||
'actions' => [
|
||||
|
||||
'remove' => [
|
||||
|
||||
Reference in New Issue
Block a user