Nice to meet you, we're Vormkracht10
Hi! We are a web development agency from Nijmegen in the Netherlands and we use Laravel for everything: advanced websites with a lot of bells and whitles and large web applications.
This package provides a FileUpload component for Filament Forms that integrates with Uploadcare for file storage. It offers a flexible and customizable file upload experience with support for multiple files, image-only uploads, and metadata handling.
You can install the package via composer:
composer require backstage/filament-uploadcare-field
Then you need to add the Uploadcare public key to your services.php
config file:
return [
'uploadcare' => [
'public_key' => env('UPLOADCARE_PUBLIC_KEY')
]
];
Warning
Do not use the Flysystem Uploadcare driver with Filament, as it may cause unexpected deletion of files. This component uses the Javascript Uploadcare widget independently of the filesystem driver.
If you want to customize the view used by the component, you can publish the views:
php artisan vendor:publish --tag="filament-uploadcare-field-views"
use Backstage\Uploadcare\Forms\Components\Uploadcare;
use Backstage\Uploadcare\Enums\Style;
public static function form(Form $form): Form
{
return $form
->schema([
Uploadcare::make('images')
->label('Images'),
]);
}
Set a custom public key for Uploadcare:
Uploadcare::make('images')
->publicKey('your-custom-key');
Set the uploader style (default is Style::INLINE
):
Uploadcare::make('images')
->uploaderStyle(Style::INLINE);
Enable multiple file uploads with optional min/max constraints:
Uploadcare::make('images')
->multiple(true, 2, 5); // Allow 2-5 files
Restrict uploads to image files only:
Uploadcare::make('images')
->imagesOnly();
Specify allowed file types:
Uploadcare::make('documents')
->accept(['image/*', 'application/pdf']);
Configure upload sources:
Uploadcare::make('images')
->sourceList(['local', 'url', 'camera', 'dropbox']);
Set the maximum file size for local uploads in bytes (default is 500MB):
Uploadcare::make('images')
->maxLocalFileSizeBytes(524288000); // 500MB
Set the maximum file size for local uploads using human-readable format:
Uploadcare::make('images')
->maxLocalFileSize('10MB'); // Supports B, KB, MB, GB, TB
Set the crop aspect ratio for images. The preset should be in format "width:height" (e.g., "1:1" for square, "16:9" for widescreen). Use an empty string for free crop:
Uploadcare::make('images')
->cropPreset('1:1'); // Square crop
Remove the Uploadcare copyright from the uploader interface. This feature is available on some paid plans:
Uploadcare::make('images')
->removeCopyright(); // Remove copyright
Include file metadata in the form data:
Uploadcare::make('images')
->withMetadata();
To handle the metadata in your form:
class EditContent extends EditRecord
{
protected static string $resource = ContentResource::class;
protected function mutateFormDataBeforeSave(array $data): array
{
if (isset($data['images'])) {
// Access metadata through $data['images']
// Process metadata as needed
}
return $data;
}
}
Here's a comprehensive example showcasing multiple features:
use Backstage\Uploadcare\Forms\Components\Uploadcare;
use Backstage\Uploadcare\Enums\Style;
public static function form(Form $form): Form
{
return $form
->schema([
Uploadcare::make('documents')
->label('Documents')
->uploaderStyle(Style::INLINE)
->multiple(true, 1, 5)
->accept(['application/pdf', 'image/*'])
->sourceList(['local', 'url'])
->withMetadata()
->columnSpanFull(),
]);
}
composer test
Please see CHANGELOG for more information on what has changed recently.
Please see CONTRIBUTING for details.
Please review our security policy on how to report security vulnerabilities.
The MIT License (MIT). Please see License File for more information.