statamic / ideas

đź’ˇDiscussions on ideas and feature requests for Statamic
https://statamic.dev
32 stars 1 forks source link

Do not lowercase my filename when uploading assets. #1198

Open geertjanknapen1 opened 1 month ago

geertjanknapen1 commented 1 month ago

For a project, I need to be able to display assets in the browser (they are PDF files). Due to these PDF files being technical documents, there are already QR codes made for these files (mywebsite.test/files/MyFile.pdf)

As you can see they are camel-cased.

When uploading an asset, Statamic does: in_array(trim(strtolower($file->getClientOriginalExtension())), $extensions). So I cannot upload files with uppercased characters in the filename. For me, this is an issue at the moment, but it's pretty niche of course.

I would like to propose a new setting on the asset container that makes us able to toggle between allowing and disallowing uppercased characters? Of course defaulting to uppercase not allowed.

Again, this is a niche problem, but maybe something other people will run into as well.


Where the code is located: src/Validation/AllowedFile/IsAllowed()

It looks like this;

private function isAllowed(UploadedFile $file): bool
{
    $extensions = array_merge($this->extensions, config('statamic.assets.additional_uploadable_extensions', []));

    return in_array(trim(strtolower($file->getClientOriginalExtension())), $extensions);
}
duncanmcclean commented 1 month ago

You can opt-out of filenames being converted to lowercase, by toggling the lowercase config option in your config/statamic/assets.php config file.

/*
|--------------------------------------------------------------------------
| Enforce Lowercase Filenames
|--------------------------------------------------------------------------
|
| Control whether asset filenames will be converted to lowercase when
| uploading and renaming. This can help you avoid file conflicts
| when working in case-insensitive filesystem environments.
|
*/

'lowercase' => true,
geertjanknapen1 commented 1 month ago

But that wouldn't be on an asset container-based level, right? If I set this to false it would happen for all my containers, right?

duncanmcclean commented 1 month ago

Correct.

There's currently no way to set it on a per-container basis. Good idea though!