bitcodr
bitcodr

Reputation: 1454

Image not show in browser with Lumen Api

I use Lumen to get images and show in browser, my code in controller is :

    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;

But image not show in browser , i just got a dark page when run that api

Upvotes: 1

Views: 1344

Answers (1)

bitcodr
bitcodr

Reputation: 1454

this code works:

    $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;

Upvotes: 1

Related Questions