mirror of
https://github.com/filamentphp/filament.git
synced 2026-09-24 15:42:09 +08:00
Merge branch '3.x' of https://github.com/filamentphp/filament into 3.x
This commit is contained in:
@@ -92,6 +92,18 @@ SpatieMediaLibraryFileUpload::make('attachments')
|
||||
->customProperties(['zip_filename_prefix' => 'folder/subfolder/'])
|
||||
```
|
||||
|
||||
### Adding custom headers
|
||||
|
||||
You may pass in custom headers when uploading files using the `customHeaders()` method:
|
||||
|
||||
```php
|
||||
use Filament\Forms\Components\SpatieMediaLibraryFileUpload;
|
||||
|
||||
SpatieMediaLibraryFileUpload::make('attachments')
|
||||
->multiple()
|
||||
->customHeaders(['CacheControl' => 'max-age=86400'])
|
||||
```
|
||||
|
||||
### Generating responsive images
|
||||
|
||||
You may [generate responsive images](https://spatie.be/docs/laravel-medialibrary/responsive-images/getting-started-with-responsive-images) when the files are uploaded using the `responsiveImages()` method:
|
||||
|
||||
+24
@@ -25,6 +25,11 @@ class SpatieMediaLibraryFileUpload extends FileUpload
|
||||
|
||||
protected string | Closure | null $mediaName = null;
|
||||
|
||||
/**
|
||||
* @var array<string, mixed> | Closure | null
|
||||
*/
|
||||
protected array | Closure | null $customHeaders = null;
|
||||
|
||||
/**
|
||||
* @var array<string, mixed> | Closure | null
|
||||
*/
|
||||
@@ -134,6 +139,7 @@ class SpatieMediaLibraryFileUpload extends FileUpload
|
||||
$filename = $component->getUploadedFileNameForStorage($file);
|
||||
|
||||
$media = $mediaAdder
|
||||
->addCustomHeaders($component->getCustomHeaders())
|
||||
->usingFileName($filename)
|
||||
->usingName($component->getMediaName($file) ?? pathinfo($file->getClientOriginalName(), PATHINFO_FILENAME))
|
||||
->storingConversionsOnDisk($component->getConversionsDisk() ?? '')
|
||||
@@ -183,6 +189,16 @@ class SpatieMediaLibraryFileUpload extends FileUpload
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string, mixed> | Closure | null $headers
|
||||
*/
|
||||
public function customHeaders(array | Closure | null $headers): static
|
||||
{
|
||||
$this->customHeaders = $headers;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string, mixed> | Closure | null $properties
|
||||
*/
|
||||
@@ -265,6 +281,14 @@ class SpatieMediaLibraryFileUpload extends FileUpload
|
||||
return $this->evaluate($this->conversionsDisk);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function getCustomHeaders(): array
|
||||
{
|
||||
return $this->evaluate($this->customHeaders) ?? [];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user