【发布时间】:2020-10-07 05:13:17
【问题描述】:
如何获取 AWS S3 图像作为流视图?
现在我可以看到如下网址:
<img src="https://s3.us-east-1.amazonaws.com/my-bucket/image.png" />
我想变成这样:
<img src="https://myproject.com/upload/image.png" />
我尝试了以下方法,但没有成功。 我的路线:
Route::get('/upload/{path_to_image}', 'FileController@getImage')->where('path', '(.*)');
-我的控制器
public function getImage($disk, $path)
{
$headers = array(
'Content-Type: application/image',
);
if(Storage::disk("s3")->exists($path))
{
$file = Storage::disk("s3")->path($path);
return response()->file($file, $headers);
}
abort(404);
}
任何建议将不胜感激!
【问题讨论】:
-
我不明白,你想用自己的 url 代替 S3 url,还是有其他问题? (我是 AWS 开发人员,对 laravel 有点了解)。
-
是的,我想要我自己的 url 而不是 AWS url。
-
“它不起作用”非常广泛。这究竟是什么意思?
标签: php laravel amazon-s3 laravel-storage laravel-filesystem