使用Response :: download()从AWS S3下载文件

时间:2013-02-03 23:13:10

标签: php amazon-web-services laravel

public function get_download($record_id)
{
    $record = Record::find($record_id);
    $file_name = $record->with_value('File Upload')->name;

    // something like https://s3.amazonaws.com/webapp/uploads/laravelsauce.png
    $file_url = read_file($record->with_value('File Upload')->value);

    return Response::download($file_url, $file_name);

    /*
    // works but why not the above
    header('Content-Type: application/octet-stream');
    header("Content-Transfer-Encoding: Binary");
    header("Content-disposition: attachment; filename='{$file_name}'");
    readfile($file_url);
    exit;
    */
}

给我:

未处理的例外

消息:

filesize()[function.filesize]:https://s3.amazonaws.com/webapp/uploads/laravelsasuce.png

的统计信息失败

1 个答案:

答案 0 :(得分:0)

解决方案:/lavel /response.php

你不能在aws文件上使用File :: size,因为File :: size()=== filesize()并且该函数无论出于何种原因都无法绘制S3文件。

enter image description here