【发布时间】:2020-05-08 02:13:41
【问题描述】:
我想在前端(Angular)中显示图像,该图像存储在 Laravel 后端。我已经尝试过。
组件.html
<img src="https://localhost:8000/images/storage/app/avatars/6.1588776952IMG_9539"/>
<div class="mb-4">
<img class="img" [src]="imgUrl">
</div>
Laravel API 路由
Route::get('images/{filename}', function ($filename)
{
$file = \Illuminate\Support\Facades\Storage::get($filename);
return response($file, 200)->header('Content-Type', 'image/jpeg');
});
【问题讨论】:
-
您是否先运行
php artisan storage:link。运行它并尝试这个<img src='{{ asset('storage/avatars/6.1588776952IMG_9539') }}'/>。还要确保您也提供图像的扩展名。在您的情况下,您没有在路径中提供图像扩展名。