Laravel 10 route return image with 404 code, if i see image, why code 404?

50 views Asked by At

I use Bearer token to secure images on site btw. In postman when i paste direct link on image, i see image, but image return with code 404, why?

My code:

/**
     * @param Request $request
     * @param string $fileName
     * @return Application|ResponseFactory|\Illuminate\Foundation\Application|Response|BinaryFileResponse
     */
    public function showTicketImage(Request $request, string $fileName)
    {
        $path = storage_path(Common::TICKET_PATH . $fileName);

        if (!file_exists($path))
            return response('', 404);

        Image::make($path);

        return response()->file($path);
    }

I also got 405 not allowed on OPTIONS method when request image, api with options work fine.

I also try:

return response('', 200)->file($path);

all same, i got my image with code 404...

I also try like that:

        $headers = [
            "HTTP/1.1 200 OK"
        ];

        return response()->file($path, $headers);

Got same 404 code.

1

There are 1 answers

0
Dmitriy On

Problem was in nginx image cache, i commented out line like expires 5d; and problem gone