Lumen Api在浏览器中无法显示图像

时间:2016-04-06 08:13:29

标签: laravel lumen

我使用Lumen获取图像并在浏览器中显示,我在控制器中的代码是:

    use Illuminate\Support\Facades\File;

    $photo = $this->uploadFile->get_by_photo($photo, ['filename']);
    $path = storage_path('app') . '/' . $photo[0]['filename'];
    $file = File::get($path);
    $type = File::mimeType($path);
    $response = response()->make($file, 200);
    $response->header("Content-Type", $type);
    return $response;

但是图片没有显示在浏览器中,我只是在运行api时有一个黑暗的页面

1 个答案:

答案 0 :(得分:1)

此代码有效:

    $photo = $this->uploadFile->get_by_photo($photo, ['filename']);
    $path = storage_path('app') . '/' . $photo[0]['filename'];
    $type = File::mimeType($path);
    $headers = array('Content-Type' => $type);
    $response = response()->download($path, $photo, $headers);
    ob_end_clean();
    return $response;