<p>I ended up using an event to accomplish this:</p>
<pre><code>use yii\base\Event;
use craft\elements\Asset;
use craft\events\AssetEvent;

Event::on(Asset::class, Asset::EVENT_BEFORE_HANDLE_FILE, function (AssetEvent $event) {
    $asset = $event-&gt;sender;
    // This does not work because it doesn't set the `uploaderId` property on the asset
    // $asset-&gt;setUploader(Craft::$app-&gt;getUser()-&gt;getIdentity()); // Doesn't work, bug?
    
    // So I just set the `uploaderId` directly
    if (is_null($asset-&gt;uploaderId)) {
        $asset-&gt;uploaderId = Craft::$app-&gt;getUser()-&gt;getId();
    }
});
</code></pre>

CC BY-SA 4.0
2020-09-06T23:05:18.663Z
2020-09-06T23:05:18.663Z
Garrett
<p>Now that Craft <a href="https://github.com/craftcms/cms/issues/3553" rel="nofollow noreferrer">keeps track</a> of which user uploaded an asset, I'm wondering if it's possible to set this information when an asset is uploaded via a frontend entry form. I have a form that includes an asset field and I would like the assets that are created to be &quot;owned&quot; by the current user. Can this be done via a hidden input, or would I need to hook into an asset event?</p>

CC BY-SA 4.0
2020-09-07T14:34:07.743Z
This is actually a [bug](https://github.com/craftcms/cms/issues/6456) in Craft. Fixed as of 3.5.8 or 3.4.30.
RitterKnight
<assets><upload><frontend-form>
Set asset uploader from frontend entry form
# Set asset uploader from frontend entry form

(Asked by: username_0 on 2020-09-06)

Now that Craft [keeps track](https://github.com/craftcms/cms/issues/3553) of which user uploaded an asset, I'm wondering if it's possible to set this information when an asset is uploaded via a frontend entry form. I have a form that includes an asset field and I would like the assets that are created to be "owned" by the current user. Can this be done via a hidden input, or would I need to hook into an asset event?

**Tags:** assets, upload, frontend-form

> **Comments:**
> **username_1**: This is actually a [bug](https://github.com/craftcms/cms/issues/6456) in Craft. Fixed as of 3.5.8 or 3.4.30.  

---

## 1 answers

### Answer by username_0 on 2020-09-06. Score: 1 | Accepted answer

I ended up using an event to accomplish this:
use yii\base\Event;
use craft\elements\Asset;
use craft\events\AssetEvent;

Event::on(Asset::class, Asset::EVENT_BEFORE_HANDLE_FILE, function (AssetEvent $event) {
    $asset = $event->sender;
    // This does not work because it doesn't set the `uploaderId` property on the asset
    // $asset->setUploader(Craft::$app->getUser()->getIdentity()); // Doesn't work, bug?
    
    // So I just set the `uploaderId` directly
    if (is_null($asset->uploaderId)) {
        $asset->uploaderId = Craft::$app->getUser()->getId();
    }
});


---

