cms
cms copied to clipboard
[4.x]: Asset filenames not saved with spaces
What happened?
Description
When uploading a file with space characters in the filename, it gets saved on the volume with dashes instead of spaces. This is a problem because the filename in the database URL encodes the spaces as %20
, but the file on the volume uses dashes, so the assets always return a 404.
I'm using DigitalOcean Spaces as my volume.
Steps to reproduce
- Upload a file with spaces in the name (ex:
This is an image.jpg
) - Output the URL of the asset in a view (ex:
{{ url }}
) - The rendered URL (
This%20is%20an%20image.jpg
) doesn't match the actual file that was uploaded to the volume (This-is-an-image.jpg
)
Expected behavior
Files uploaded to the volume should retain spaces (This is an image.jpg
)
Actual behavior
Files uploaded to the volume replace spaces with dashes (This-is-an-image.jpg
)
Craft CMS version
4.0.5
PHP version
8.1.4
Operating system and version
Darwin 21.5.0
Database type and version
MySQL 8.0.28
Image driver and version
GD 8.1.4
Installed plugins and versions
- Control Panel Nav: 4.0.2
- DigitalOcean Spaces Filesystem: 2.0.0
- Expanded Singles: 2.0.0-beta.1
- Feed Me: 5.0.4
- Redactor: 3.0.0
- Super Table: 3.0.0-beta.6
I’m not able to reproduce this. How are you uploading the files, exactly?
Also, are you overriding the convertFilenamesToAscii
or filenameWordSeparator
config settings?
Oh wow, I didn't see that there was a preference for this! Changing filenameWordSeparator
to false
fixed the issue. It might make sense to either have this be true
by default, or at least have the URL returned by the asset match the uploaded file. Thanks for the quick response!
@andyra I’d still like to get to the bottom of why the URLs are incorrect, though. When I leave the setting to its default value ('-'
), uploaded asset URLs reflect their filenames, with dashes.
So can you tell me how you are uploading the assets? And for assets where this issue occurred, do their filenames in the control panel show dashes or spaces?
I tried creating assets from the Assets page in the CP, via an Asset field (within a Matrix block), and via a FeedMe import, and they all had the same issue.
The filenames in the CP all had spaces. The only reason I knew they were saved with dashes was by looking on the Spaces volume on my Digital Ocean account.
We’re still unable to reproduce, either with a Local filesystem or with DO Spaces. Going to leave the issue open in case anyone else runs into it. Maybe another clue will come up.