I want to change the filename before the file is stored, to prevent ugly, long and weird filenames uploaded by users.
I've found an example for Craft 2, but because of the changes for events I can't rebuild this for Craft 3 (Change asset name on upload)
I also tried to change it a event, no luck;
Event::on(
Asset::class,
Asset::EVENT_BEFORE_HANDLE_FILE,
function(AssetEvent $event) {
$asset = $event->asset;
$filename = 'filename'.md5(time()).'.'.$asset->getExtension();
$asset->filename = $filename;
}
);
Apparently the filename property is read-only, so you can only change properties like the title.
Any help is appreciated!