Plugin uploads an asset, need the final url I have a plugin which


uploads one or more files
creates a new entry with those files as new assets in a subfolder whose name is the new entry's slug
sends e-mail which includes links to the new assets.


The problem I have is that the url for the new assets is not their final url (in the subfolder), but /cpresources/tempassets/field_###/filename

The relevant bit of code:

if (craft()-&gt;entries-&gt;saveEntry($entry))
{
  // send the e-mail
  ... here when I send the e-mail, the url is wrong ...
}


What do I need to do after the saveEntry?
I think your best bet here would be to make use of the entries.onSaveEntry event, because at the moment $entry doesn't relate to the entry you have just saved, but the entry you wanted to save so it makes sense the entry asset paths are still pointing to the temp locations.

As far as i'm aware craft()-&gt;entries-&gt;saveEntry() just returns a bool, whether or not the save was a success, and not the entry model that was just saved.

So your controller could look like this:

if (!craft()-&gt;entries-&gt;saveEntry($entry))
{
 // Only worry if something goes wrong
}


Then in an init function in your main plugin class you could do something like:

craft()-&gt;on('entries.saveEntry', function(Event $event){

 // Is this a new entry?
 if($event-&gt;params['isNewEntry'])
 {
    // This is an EntryModel object of the entry that was just saved
    $entry = $event-&gt;params['entry'];

    // Is the entry in the right section?
    if($entry-&gt;sectionId == 1)
    {
      // Send the $entry to your email function
      craft()-&gt;yourPlugin-&gt;sendEmail($entry);
    }
 }

});


I would assume at this point the asset paths are all correct as it would have been saved to the database and all the backend work done etc

This would help you out in the future as well as it wouldn't matter where the entry was created, whether in the admin or through your plugin or anywhere else, and you could be sure the email will still get triggered :)

Failing that you could also try the assets.onSaveAsset event and see if you get better results with that?

http://buildwithcraft.com/docs/plugins/events-reference

I hope this helps in some way!