filament-tinyeditor icon indicating copy to clipboard operation
filament-tinyeditor copied to clipboard

Keep the Original Filename When Uploading Images

Open sumonranapro opened this issue 11 months ago • 2 comments

I am trying to upload an image via Filament TinyEditor and I would like to retain the original filename of the image when it is uploaded. However, the image is being uploaded with a random filename.

Could you please provide guidance on how to keep the original filename when uploading a new image through the editor?

Image

sumonranapro avatar Jan 31 '25 22:01 sumonranapro

Did you find any solution for it?

sjsiam avatar Jul 05 '25 20:07 sjsiam

I just figured it out, if you want to keep the original file name add your own ->saveUploadedFileAttachmentsUsing() callback. I used this, this example creates a slug of the original filename with an underscore as the seperator.

<?php

TinyEditor::make('content')
    ->label('Content')
    ->saveUploadedFileAttachmentsUsing(
        function (TemporaryUploadedFile $file) {
            $originalName = $file->getClientOriginalName();
            $pathInfo = pathinfo($originalName);
            $extension = $pathInfo['extension'] ?? '';
            $filename = $pathInfo['filename'] ?? $originalName;
    
            $sluggedName = Str::slug($filename, '_') . '.' . $extension;
            return $file->storeAs('uploads', $sluggedName, 'public');
        }
    ),

DaniWinter avatar Sep 11 '25 14:09 DaniWinter