Fixing Attachment Uploads with Filament's Markdown Editor on Laravel Cloud
Tutorials

Fixing Attachment Uploads with Filament's Markdown Editor on Laravel Cloud

Published on Mar 13, 2025

Laravel Cloud provides an excellent hosting solution that integrates seamlessly with Cloudflare's R2 object storage. When combined with Filament's markdown editor, you have a nice system for attachments. However, there's a specific challenge when dealing with uploads with this setup.

The Problem

Unable to retrieve the visibility for file at location

When using Filament's markdown editor with private file visibility settings, you might encounter an "Unable to retrieve the visibility for file at location" error related to file visibility checks. This occurs because:

  • The markdown editor attempts to generate a URL for private files
  • During this process, it checks the file visibility using the GetObjectAcl command
  • Cloudflare R2 doesn't support the GetObjectAcl command, causing the URL generation to fail

The Solution

To resolve this issue, we need to override the default behavior of the markdown editor's attachment URL generation. Here's how to implement the fix:

use Filament\\Forms\\Components\\MarkdownEditor;

class YourResource extends Resource
{
    public static function form(Form $form): Form
    {
        return $form
            ->schema([
                MarkdownEditor::make('content')
                    ->fileAttachmentsDisk(config('filament.default_filesystem_disk'))
					->fileAttachmentsDirectory('attachments')
					->fileAttachmentsVisibility('private')
					->getUploadedAttachmentUrlUsing(function ($file): ?string {
							/** @var FilesystemAdapter $storage */
							$storage = \Storage::disk(config('filament.default_filesystem_disk'));

							try {
									if (! $storage->exists($file)) {
											return null;
									}
							} catch (UnableToCheckFileExistence $exception) {
									return null;
							}

							return $storage->url($file);
					})
            ]);
    }
}

How It Works

This solution works by:

  • Overriding the getUploadedAttachmentUrlUsing method on the markdown editor
  • Bypassing the default visibility check mechanism
  • Directly generating and returning the URL for the uploaded file

Conclusion

This workaround serves as the best solution until either visibility checks match S3's driver capabilities or the file system fully adapts to R2 storage.

Latest Posts

Others You May Like