Limit asset upload size


Is it currently possible to limit the size of uploaded assets? Preferably specify a limit per user/group?

My user base is not very tech savvy and they keep uploading assets of 20MB and very large resolutions.


Can’t you just edit the max uploadsize limit in the php.ini?


Yes, if I want to set the maximum file size for all users.

I want to set file size and picture dimension limits for a set of users, or at least change it globally from within cockpit.

For now I will have to do with just max file size.


you can try to hook into in your custom bootstrap.php:


//triggered before are assets saved to db
$app->on('', function(&$assets) {
   // check code


It seems possible to limit in the save hook, but if we have already a validation for the upload type why not have one for file size! I created the PR that adds a file size check,
therefore I think the error messages could be improved.

Update: validating on seems too late and it will cause an unpexected behaviour, for example if inserting just one and we remove it from the array we’ll end up with an empty insert with null values. It seems more sensible to have a new hook on uploadAssets()

Update2: or deal with the possibility of the existing cockpit.asset.upload hook to unset the asset and not proceed with the save (PR was updated for that scenario)