ideas
ideas copied to clipboard
Assets: Global Rules/Validation + CP Default Rules
Recently we had a content editor accidentally upload a large .psd file directly into the CP via the Assets screen. This mean that all the individual field validation rules were ignored. This made me think of a couple of suggestions:
- It would be nice to be able to set default/global validation rules for uploads that apply to the CP
- Groups or sets of rules that can be shared across fields, so I could set validation rules for 'Large Images' or 'Videos' apply it to certain fields without having to copy/paste or update rules across all uses of the field after the fact.
Very much a nice to have, obviously not a big issue.
We've mentioned this plenty of times but I can't find an issue for it.
The idea was to always be able to add validation rules to the container.
I would go further to say that this is a medium sized issue. If you've ever tried processing a 20mb image with glide and generating reponsive sizes / fallbacks you might see a website grind to a halt for a while, and possibly crash a server / require a restart.
Also, are PHP validation rules what we need here? In an ideal situation I would catch the large file size with JS validation before sending it to the server or to cloud storage.
Just some thoughts.
That's a good idea too. To stop the large file getting to the server in the first place. 👍
While we're on the subject, there are a couple of more validation rules that would help me avoid asset related crashes:
- File type: A client uploaded a PDF to my 'images' container, and glide crashed the website when trying to make a thumbnail from it. A list of allowed file / mime types would prevent this.
- File name: A client uploaded a file with a very strange name - it included semicolons (which I think conflict with Statamic's asset ids) and lots of full-stops. Again glide crashed when trying to handle this file. Regex filename validation would prevent this, or maybe just prevent semi-colons in filenames globally.
I've been reading other issues and requests from v2 and there are concerns about resizing originals on upload - with some stating that they think original sizes should be kept. Container validation rules should keep everyone happy, giving you the option to resize / restrict or not. I wonder though, would it be possible to always keep the original file, generate a smaller size where necessary and then use that smaller size for glide generation, i.e. the original massive file would be kept but a smaller version would be used by glide for performance.