Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allowedFileExtensions and fileKinds not synced #3917

Closed
missmatsuko opened this issue Feb 26, 2019 · 3 comments

Comments

Projects
None yet
2 participants
@missmatsuko
Copy link
Contributor

commented Feb 26, 2019

Description

The asset field in the CMS comes with preset file types, but the extensions for these types aren't all allowed by default:

It's kind of weird that you can select a file type to be allowed in the CMS, but they can't actually be uploaded since those extensions don't match up with allowedFileExtensions. JSON was like this and fixed in #3254, but there's still many differences between the two extension sets. Some entire fileKinds like Access and PHP don't have any of their extensions in allowedFileExtensions.

I also think it could be handy to be able to define fileKinds from scratch. For example, I might not want so many fileKinds to choose from when making an assets field. e.g. I'll likely never need uploadable Access, Illustrator, Photoshop files, so I might want to remove them. Or, I might want to combine or split some of the built-in fileKinds (e.g. maybe "Code" fileKind that covers PHP, JS, and HTML, or split "Image" into "Photo/Raster" and "Illustration/Vector").

Is there a reason why the built-in fileKinds are hard-coded and extendable with extraFileKinds rather than having a default value that can be overwritten like allowedFileExtensions?

Related: #3254 #3131

Steps to reproduce

n/a

Additional info

  • Craft version: 3.x.x
  • PHP version:
  • Database driver & version:
  • Plugins & versions:
@brandonkelly

This comment has been minimized.

Copy link
Member

commented Feb 27, 2019

It's kind of weird that you can select a file type to be allowed in the CMS, but they can't actually be uploaded since those extensions don't match up with allowedFileExtensions

Agree that’s awkward. Maybe we can limit the asset setting to only show file kinds that contain uploadable file extensions.

Is there a reason why the built-in fileKinds are hard-coded and extendable with extraFileKinds rather than having a default value that can be overwritten like allowedFileExtensions?

Doesn’t make a ton of sense to make the whole thing customizable, since it’s not like a .mp3 file is going to mean a different thing on different websites.

@missmatsuko

This comment has been minimized.

Copy link
Contributor Author

commented Feb 27, 2019

Agree that’s awkward. Maybe we can limit the asset setting to only show file kinds that contain uploadable file extensions.

Yes, I think this should be done, at least.

Doesn’t make a ton of sense to make the whole thing customizable, since it’s not like a .mp3 file is going to mean a different thing on different websites.

Even with the pre-set "audio" file kind, though... It's true all those file extensions are for audio files, but if I'm using the audio file as the source for a front-end HTML5 audio player, for cross-browser support I probably want content authors to only be able to upload MP3, FLAC, and WAV files (unless I'm converting file types in the backend anyways).

Currently, I would have to make a new file kind for web audio only, or disallow the unwanted file extensions for the whole site. I guess that's fine for the most part?

It still seems a bit weird for me to have file kinds and file extensions managed separately, since fileKinds already contains file extensions which could be used as the value for allowableFileExtensions?

If I add a new file kind, I have update extraFileKinds and check extraAllowedFileExtensions/allowedFileExtensions to see if the extensions are allowed. Maybe a reminder for this should be added to the docs?

@brandonkelly

This comment has been minimized.

Copy link
Member

commented Feb 27, 2019

Added that change to Assets fields for the next release.

Currently, I would have to make a new file kind for web audio only, or disallow the unwanted file extensions for the whole site. I guess that's fine for the most part?

Yep, you could define a “Web Audio” file kind using the extraFileKinds config setting.

It still seems a bit weird for me to have file kinds and file extensions managed separately, since fileKinds already contains file extensions which could be used as the value for allowableFileExtensions?

Well, the full list of file kinds is mainly for Craft’s own reference. Similar to knowing all the MIME types, even if there’s types in there that aren’t actually allowed to be uploaded. There could be other cases unrelated to uploading where Craft needs to know what type of file something is. (Even with assets – it’s possible to circumvent the allowedFileExtensions config setting if you upload a file to your volume directly and then run the Asset Indexes utility.)

If I add a new file kind, I have update extraFileKinds and check extraAllowedFileExtensions/allowedFileExtensions to see if the extensions are allowed. Maybe a reminder for this should be added to the docs?

Yeah good call. Added a tip about this to the extraFileKinds config setting docs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.