How to rename filename of asset before (or after) upload in Craft 3 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-&gt;asset;                         
        $filename = 'filename'.md5(time()).'.'.$asset-&gt;getExtension();
        $asset-&gt;filename = $filename;
    }
);


Apparently the filename property is read-only, so you can only change properties like the title.

Any help is appreciated!
Well, after searching for this for more than 2 hours, I bumped into a working solution;

Event::on(
    Elements::class,
    Elements::EVENT_AFTER_SAVE_ELEMENT,
    function(ElementEvent $event)   {

        $asset = $event-&gt;element;

        if ($event-&gt;isNew &amp;&amp; $asset instanceof craft\elements\Asset) {
            $newFileName = 'file-'.md5(time()).'.'.$asset-&gt;getExtension();
            Craft::$app-&gt;assets-&gt;moveAsset($asset, $asset-&gt;getFolder(), $newFileName);
        }
    }
);


In case somebody needs it!