This commit is contained in:
Dan Harrin
2023-10-16 11:50:44 +01:00
2 changed files with 36 additions and 0 deletions
@@ -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:
@@ -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>
*/