How to rename filename of asset before (or after) upload in Craft 3
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!