<p>I am using a miss match of what I have found across SE but I'm not really getting anywhere doing this form my module in Craft 3.</p>
<p><strong>What I would like to achieve:</strong>
When a user uploads an asset to a custom field in their account, I'd like to rename that asset to be their company name (companyName custom field)</p>
<p>Any help/direction appreciated.</p>
<pre><code>    Event::on(
        User::class,
        User::EVENT_AFTER_SAVE,
        function (ModelEvent $event) {     
            
            //Set value of custom field
            $companyName = Craft::$app-&gt;getUser()-&gt;getIdentity()-&gt;getFieldValue('companyName');
            $assetFileModels = Craft::$app-&gt;getUser()-&gt;getIdentity()-&gt;getFieldValue('companyLogo');
            
            foreach ($assetFileModels as $assetFileModel)                
            {
                $newFileName = $companyName;
                Craft::$app-&gt;assets-&gt;moveAsset($assetFileModel, $assetFileModel-&gt;getFolder(), $newFileName);
                
            }
            
            
        }
    );
</code></pre>

<craft3>
Renaming an Asset in User Account on upload
# Renaming an Asset in User Account on upload

(Asked by: username_0 on 2023-03-23)

I am using a miss match of what I have found across SE but I'm not really getting anywhere doing this form my module in Craft 3.
What I would like to achieve:
When a user uploads an asset to a custom field in their account, I'd like to rename that asset to be their company name (companyName custom field)
Any help/direction appreciated.
    Event::on(
        User::class,
        User::EVENT_AFTER_SAVE,
        function (ModelEvent $event) {     
            
            //Set value of custom field
            $companyName = Craft::$app->getUser()->getIdentity()->getFieldValue('companyName');
            $assetFileModels = Craft::$app->getUser()->getIdentity()->getFieldValue('companyLogo');
            
            foreach ($assetFileModels as $assetFileModel)                
            {
                $newFileName = $companyName;
                Craft::$app->assets->moveAsset($assetFileModel, $assetFileModel->getFolder(), $newFileName);
                
            }
            
            
        }
    );

**Tags:** craft3

---

## 0 answers

