Answers.Body: <p>You could try to use a task, to make sure the upload is completed before redirecting.</p>
  
  <p>Here is a good starting point on how to use a task:
  <a href="https://craftcms.stackexchange.com/questions/8399/documentation-on-creating-tasks">Documentation on creating tasks</a></p>
  
  <p>Basically you define the steps of a task, in you case I guess 2. The next step of a task is started when the last step returned true.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-05-17T11:25:50.630Z
Answers.LastActivityDate: 2017-05-17T11:25:50.630Z
Answers.UserDisplayName: Max Strebel
Body: <p>I'm trying to redirect at the end of the saveasset function in init().</p>
  
  <p>This is my code:</p>
  
  <pre><code>craft()-&gt;on('assets.saveAsset', function (Event $event) {
  
       // a lot of code here ##########################
  
       //#############################################
  
       //at the end:
  
       craft()-&gt;request-&gt;redirect('myurl.com'); 
  }
  </code></pre>
  
  <p>When I save an asset with the redirect function at the end I get the following alert:</p>
  
  <p>Upload failed for filename.csv.</p>
  
  <p>The upload works when I leave the redirect out.</p>
  
  <p>Thanks!</p>
  
Tags: <plugin-development><assets>
Title: Redirect after saveAsset in plugin
ThreadText: # Redirect after saveAsset in plugin
  
  (Asked by: username_0 on 2017-05-17)
  
  I'm trying to redirect at the end of the saveasset function in init().
  
  This is my code:
  
  ```
  craft()->on('assets.saveAsset', function (Event $event) {
  
       // a lot of code here ##########################
  
       //#############################################
  
       //at the end:
  
       craft()->request->redirect('myurl.com'); 
  }
  
  ```
  
  When I save an asset with the redirect function at the end I get the following alert:
  
  Upload failed for filename.csv.
  
  The upload works when I leave the redirect out.
  
  Thanks!
  
  **Tags:** plugin-development, assets
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2017-05-17. Score: 1
  
  You could try to use a task, to make sure the upload is completed before redirecting.
  
  Here is a good starting point on how to use a task:
  [Documentation on creating tasks](https://craftcms.stackexchange.com/questions/8399/documentation-on-creating-tasks)
  
  Basically you define the steps of a task, in you case I guess 2. The next step of a task is started when the last step returned true.
  
  
  ---
  
  