cms icon indicating copy to clipboard operation
cms copied to clipboard

[4.x]: Asset filenames not saved with spaces

Open andyra opened this issue 2 years ago • 5 comments

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

  1. Upload a file with spaces in the name (ex: This is an image.jpg)
  2. Output the URL of the asset in a view (ex: {{ url }})
  3. 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

andyra avatar Jun 21 '22 23:06 andyra

I’m not able to reproduce this. How are you uploading the files, exactly?

Also, are you overriding the convertFilenamesToAscii or filenameWordSeparator config settings?

brandonkelly avatar Jun 22 '22 05:06 brandonkelly

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 avatar Jun 22 '22 15:06 andyra

@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?

brandonkelly avatar Jun 22 '22 17:06 brandonkelly

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.

andyra avatar Jun 23 '22 22:06 andyra

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.

brandonkelly avatar Jun 24 '22 17:06 brandonkelly