> ## Documentation Index
> Fetch the complete documentation index at: https://flex-fields.bjanczak.com/llms.txt
> Use this file to discover all available pages before exploring further.

> ## Agent Instructions
> Examples target Filament 5. Verify optional dependencies before configuring integrations.
> Upload transfer completion, permanent storage and record acceptance are separate milestones. Native and Spatie image conversions retain the original.

# FLEX Media Studio integration

> Connect FLEX FileUpload and FlexRichEditor to a shared Studio workspace for uploads, file selection and image reuse.

[FLEX Media Studio](https://studio.bjanczak.com/) is a self-hosted media library for Laravel and Filament. Connect it to FLEX Fields to upload directly into a workspace, choose an existing file, or insert library images into rich text. FLEX Fields handles the form and editor interface. Media Studio handles permissions, storage, version references and configured renditions.

## Install and authorize Media Studio

Install Media Studio alongside FLEX Fields and publish its matching Laravel migrations, configuration and browser assets. Follow the [Media Studio installation guide](https://studio.bjanczak.com/installation) and the [FLEX Fields integration setup](https://studio.bjanczak.com/flex-fields/setup). FLEX Fields continues to support its local disk and Spatie upload modes independently.

### Find your workspace ID

Open Media Studio in your own application and select the workspace you want to use, such as **Media library**. In the address bar, copy the value of the `fmsWorkspace` parameter. If the address does not show it yet, open a folder in the workspace and check again. With Studio URL synchronization enabled, the address will look like this:

```text theme={"theme":{"light":"github-light","dark":"github-dark"}}
https://app.example.com/admin/media-studio?fmsWorkspace=01ARZ3NDEKTSV4RRFFQ69G5FAV&fmsFolder=01ARZ3NDEKTSV4RRFFQ69G5FAW
```

In this example, the workspace ID is `01ARZ3NDEKTSV4RRFFQ69G5FAV`. To choose an upload destination or folder scope, open that folder and copy its `fmsFolder` value. Use the values from your own installation.

For a field that always uses one workspace, store the ID in your application config:

```php theme={"theme":{"light":"github-light","dark":"github-dark"}}
// config/studio-integration.php
return [
    'workspace_id' => env('STUDIO_WORKSPACE_ID'),
];
```

Set `STUDIO_WORKSPACE_ID` in the host application and pass `workspace: config('studio-integration.workspace_id')` to `studio()`. Use a closure when the ID is determined per request, for example from the current Filament tenant's workspace mapping. Embedded views with URL synchronization disabled can use the `id` returned by [Studio's authenticated workspace endpoint](https://studio.bjanczak.com/flex-fields/setup#prepare-an-authorized-workspace).

The actor must have access to the configured workspace. Uploads also require Studio upload permissions.

## Let users upload or choose an existing file

```php theme={"theme":{"light":"github-light","dark":"github-dark"}}
use Bjanczak\FilamentFlexFields\Filament\Forms\Components\FlexFileUpload;
use UseFlex\MediaStudio\Integrations\Filament\StudioPicker;

FlexFileUpload::mediaStudio('gallery')
    ->studio(
        workspace: config('studio-integration.workspace_id'),
        moduleUrl: asset('vendor/media-studio/studio.js'),
        stylesheetUrl: asset('vendor/media-studio/studio.css'),
        uploadFolder: fn () => $destinationFolderId,
        acceptedMimeTypes: ['image/jpeg', 'image/png', 'image/webp'],
    )
    ->studioScopedFolder(fn () => $allowedRootId)
    ->configureStudioPickerUsing(
        fn (StudioPicker $picker) => $picker
            ->pickerLayout('folders')
            ->rememberLocation(workspace: false, folder: true, key: 'product-gallery'),
    )
    ->multiple()
    ->maxFiles(8)
    ->uploadLayout('grid')
    ->reorderable();
```

**Upload file** sends validated bytes to the configured workspace and folder. **Choose media** opens Studio and stores the selected asset and version reference. Selecting an existing asset leaves the stored original in place.

| Control | Effect |
| - | - |
| `studioUpload(false)` | Keep library selection available and disable new uploads from the field. |
| `studioLibrarySelection(false)` | Offer the upload workflow only. |
| `allowPickerUpload(true)` | Offer uploads inside the picker, subject to field configuration and the actor's Studio permissions. |
| `studioScopedFolder($root)` | Restrict the field to a folder subtree. Set its upload destination within that scope. |
| `acceptedMimeTypes: ['application/pdf']` | Restrict selection and upload to PDFs. |
| `persistStudioUploadsImmediately(false)` | Defer publication of new files until the form is saved. |
| `studioThumbnailPreset('thumbnail-v1')` | Use a named Studio conversion for card thumbnails when the conversion is available. |

The picker can show a compact layout, folders, or a workspace and folder sidebar. See [all picker and upload settings](https://studio.bjanczak.com/flex-fields/configuration) and [Filament tenant setup](https://studio.bjanczak.com/filament-tenancy). Storage settings such as the private S3 disk and conversion recipes belong to Media Studio. Folder IDs select the destination within Studio.

## Insert library images with FlexRichEditor

Use the same workspace configured for the upload field.

```php theme={"theme":{"light":"github-light","dark":"github-dark"}}
use Bjanczak\FilamentFlexFields\Filament\Forms\Components\FlexRichEditor;
use UseFlex\MediaStudio\Integrations\Filament\RichEditorStudioPlugin;

FlexRichEditor::make('body')
    ->plugins([
        new RichEditorStudioPlugin(
            workspace: config('studio-integration.workspace_id'),
            moduleUrl: asset('vendor/media-studio/studio.js'),
            stylesheetUrl: asset('vendor/media-studio/studio.css'),
            allowUpload: false,
        ),
    ])
    ->toolbarButtons([
        ['bold', 'italic', 'link'],
        [RichEditorStudioPlugin::TOOL],
    ]);
```

The toolbar action opens Studio at the configured workspace. This setup inserts existing images. See the [RichEditor integration guide](https://studio.bjanczak.com/filament-rich-editor) for image formats, ready renditions and attachment ID configuration.

## Save references and edited images

A single FileUpload selection stores a nullable `assetId:versionId` string. For a multiple field, store the ordered references in a JSON column with an array cast. Register application usages when saving the owning record so Studio can protect actively used versions. Removing a selection from the field leaves the Studio asset available. See [reference persistence](https://studio.bjanczak.com/filament-media-references).

Use Studio's version publisher when wiring classic or AI image edits into a Studio-backed field. Save the edit after the user chooses the result, and configure thumbnail generation and previous-version retention for your workflow. See [classic and AI editors for Studio uploads](https://studio.bjanczak.com/filament-flex-file-upload) and the [FLEX AI editor guide](https://flex-fields.bjanczak.com/docs/file-upload-ai-image-editor.md).


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.