Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

marcoplus's avatar

Api upload image An Error Occurred: Not Found

In my api I inserted this code, but when I try with postman I receive this error, but I don't understand where the mistake is and why it doesn't work

<div class="container">
        <h1>Oops! An Error Occurred</h1>
        <h2>The server returned a "404 Not Found".</h2>

        <p>
            Something is broken. Please let us know what you were doing when this error occurred.
            We will fix it as soon as possible. Sorry for any inconvenience caused.
        </p>
    </div>
public function upload(Request $request)
    {
        try {
            $photo = $request->file("image");
            if($photo != null){
                $ext = $photo->getClientOriginalExtension();
                $fileName = rand(10000, 50000) . '.' . $ext;
                if($ext == 'jpg' || $ext == 'JPG' || $ext == 'jpeg' || $ext == 'JPEG' || $ext == 'PNG' || $ext == 'png' || $ext == 'GIF' || $ext == 'gif'){
                    if($photo->move(public_path().'/uploadedphotos', $fileName)){
                        $porte = Porte::find($request->input('id'));
                        $porte->image = url('/') . "/public/uploadedphotos" . "/" . $fileName;
                        $porte->save();
                        return response(['result' => true]);
                    }
                    return response(['result' => false]);
                }
            } else{
                return response(['result' => false]);
            }
        } catch (\Exception $exception){
            return $exception->getMessage();
        }
    }
0 likes
8 replies
tisuchi's avatar

@marcoplus Can you first make sure that you have this route /api/upload (I assume)?

2 likes
marcoplus's avatar

@tisuchi yes I created the route

Oops! An Error Occurred
The server returned a "405 Method Not Allowed".
Something is broken. Please let us know what you were doing when this error occurred. We will fix it as soon as possible. Sorry for any inconvenience caused.
1 like
tisuchi's avatar

@marcoplus Then I assume your /api/upload route is the POST route, correct?

If so, in the postman, you might use the GET method instead of POST.

This means you need to use the POST method in the postman.

2 likes
marcoplus's avatar

@tisuchi Unfortunately it is not like that, I was hoping for a similar error to solve the problem immediately, but the request is correct Senza-titolo.png

1 like
tisuchi's avatar

@marcoplus can you show your route list output from this command?

php artisan route:list
2 likes
tisuchi's avatar
tisuchi
Best Answer
Level 70

@marcoplus there is a high possibility that your /api/porte-upload route is conflicted with other route.

I would like to ask you to share your whole route list without remove anything (if possible).

Can you also just dumping something in the beginning of the method?

public function upload(Request $request)   
{
    dd("I am here");
}
3 likes
marcoplus's avatar

@tisuchi thanks what you said made me change the route and now it works, thanks for your always valid support

{
    "result": true
}

1 like

Please or to participate in this conversation.