Body: <p>Admin users can replace asset files without having to deal with re-uploading/re-creating a new asset using the feature/technique described in Peter's answer here: <a href="https://craftcms.stackexchange.com/questions/1550/is-it-possible-to-replace-uploaded-assets">Is it possible to replace uploaded assets?</a>. This has the advantage of preserving any values in the asset's custom fields.</p>
  
  <p>I need to populate some of those fields dynamically though, so they correspond to the new file for the asset. So, I wrote a small plugin that listens to the <a href="https://craftcms.com/docs/plugins/events-reference#assets-onReplaceFile" rel="nofollow noreferrer">assets.onReplaceFile</a> event like so:</p>
  
  <pre><code>craft()-&gt;on('assets.replaceFile', function(Event $event) {
    Craft::dd($event-&gt;params); // or whatever
  });
  </code></pre>
  
  <p>But the code in the handler never gets executed. Is this the right event to listen to this specific user action or is there another event for it? Or am I doing something wrong here? Thanks!</p>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2016-11-10T23:54:29.330Z
Comments.Text: Where does that code live?  In your plugin's `init()` method?
Comments.UserDisplayName: Brad Bell
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2016-11-12T17:18:01.623Z
Comments.Text: Yes, in the `init()` method of the plugin's main class.
Comments.UserDisplayName: yoannisj
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2016-11-13T04:51:36.957Z
Comments.Text: Can you describe the workflow you're using where you're expecting the event to get fired?
Comments.UserDisplayName: Brad Bell
Tags: <plugin-development><assets><control-panel><replace>
Title: Listen to replacing files through CP's assets section
ThreadText: # Listen to replacing files through CP's assets section
  
  (Asked by: username_0 on 2016-11-10)
  
  Admin users can replace asset files without having to deal with re-uploading/re-creating a new asset using the feature/technique described in Peter's answer here: [Is it possible to replace uploaded assets?](https://craftcms.stackexchange.com/questions/1550/is-it-possible-to-replace-uploaded-assets). This has the advantage of preserving any values in the asset's custom fields.
  
  I need to populate some of those fields dynamically though, so they correspond to the new file for the asset. So, I wrote a small plugin that listens to the [assets.onReplaceFile](https://craftcms.com/docs/plugins/events-reference#assets-onReplaceFile) event like so:
  
  ```
  craft()->on('assets.replaceFile', function(Event $event) {
    Craft::dd($event->params); // or whatever
  });
  
  ```
  
  But the code in the handler never gets executed. Is this the right event to listen to this specific user action or is there another event for it? Or am I doing something wrong here? Thanks!
  
  **Tags:** plugin-development, assets, control-panel, replace
  
  > **Comments:**
  > **username_1**: Where does that code live?  In your plugin's `init()` method?  
  > **username_0**: Yes, in the `init()` method of the plugin's main class.  
  > **username_1**: Can you describe the workflow you're using where you're expecting the event to get fired?  
  
  ---
  
  ## 0 answers
  
  