backstage/filament-uploadcare-field

Uploadcare FileUpload component for Filament Forms

Fund package maintenance!
vormkracht10

Installs: 13

Dependents: 0

Suggesters: 0

Security: 0

Stars: 2

Watchers: 2

Forks: 0

Open Issues: 3

Language:JavaScript

v0.2.2 2025-04-15 08:38 UTC

README

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status Total Downloads

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.

About the package

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.

Our other Uploadcare related packages

Installation

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.

Customization

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"

Basic Usage

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'),
        ]);
}

Available Methods

Configuration Methods

publicKey(string $publicKey)

Set a custom public key for Uploadcare:

Uploadcare::make('images')
    ->publicKey('your-custom-key');

uploaderStyle(Style $style)

Set the uploader style (default is Style::INLINE):

Uploadcare::make('images')
    ->uploaderStyle(Style::INLINE);

File Upload Options

multiple(bool $multiple = true, int $min = 0, int $max = 0)

Enable multiple file uploads with optional min/max constraints:

Uploadcare::make('images')
    ->multiple(true, 2, 5); // Allow 2-5 files

imagesOnly(bool $imgOnly = true)

Restrict uploads to image files only:

Uploadcare::make('images')
    ->imagesOnly();

accept(array|string $accept)

Specify allowed file types:

Uploadcare::make('documents')
    ->accept(['image/*', 'application/pdf']);

sourceList(array|string $sourceList)

Configure upload sources:

Uploadcare::make('images')
    ->sourceList(['local', 'url', 'camera', 'dropbox']);

Metadata Handling

withMetadata(bool $withMetadata = true)

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;
    }
}

Complete Example

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(),
        ]);
}

Testing

composer test

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

Credits

License

The MIT License (MIT). Please see License File for more information.