Can a plugin force download an asset from third-party source like Amazon S3? I have created a plugin that takes a form post, retrieves an asset id and am trying to have the browser start the download process. Is this possible if using a third party source like AmazonS3?  If so what may be wrong with this plugin controller method?

public function actionDownloadAsset()
{
    $this-&gt;requirePostRequest();
    $id = craft()-&gt;request-&gt;getRequiredPost("id");

    $attributes = array('id' =&gt; $id);
    $element = craft()-&gt;elements-&gt;getCriteria(ElementType::Asset)-&gt;limit(1)-&gt;find($attributes);

    header('Content-Description: File Transfer');
    header('Content-Type: application/octet-stream');
    header('Content-Disposition: attachment; filename='.basename($element-&gt;filename));
    header('Content-Transfer-Encoding: binary');
    header('Expires: 0');
    header('Cache-Control: must-revalidate');
    header('Pragma: public');
    header('Content-Length: ' . $element-&gt;filesize);
    readfile($element-&gt;url);
}


Everytime I try the plugin from front end I get a page not found.  I have made sure the from is posting to the controller method.
I have found a solution. 

public function actionDownloadAsset()
{
  $this-&gt;requirePostRequest();
  $id = craft()-&gt;request-&gt;getRequiredPost("id");
  $attributes = array('id' =&gt; $id);
  $element = craft()-&gt;elements-&gt;getCriteria(ElementType::Asset)-&gt;first($attributes);


  $file = $entry-&gt;url;
  $name = $entry-&gt;filename;

  header('Content-Description: File Transfer');
  header('Content-Type: application/octet-stream');
  header('Content-Disposition: attachment; filename='.basename($name));
  header('Content-Transfer-Encoding: binary');
  header('Expires: 0');
  header('Cache-Control: must-revalidate');
  header('Pragma: public');

  readfile($file);
}


To get access to the file url I had to array_shift the $element returned from getCriteria.  Then I had to exclude the file size header. This was ultimately causing the "this webpage is not available". Not sure the reason. 

header('Content-Length: ' . filesize($entry-&gt;size))