0
votes

I'm trying to upload an image file . When i am calling my API to upload file using postman , getting error like Fatal error: Call to a member function file() on array.

I could not post this file to my Laravel controller .How to post files in Laravel. Anyone could help me to solve this issue?

Here is my controller function,

public function edit(Request $request){

    $request = $request->input();
    if(empty($request)) {
        $request = json_decode(file_get_contents('php://input'),true);
    }

    $to_return = array();

    $file = $request->file('files'); 
}

at this line $file = $request->file('files'); getting fatal error.

4
code indentation improvementLakhwinder Singh

4 Answers

0
votes

set method as post .. and at body ... change to option from form data to w-xxx-formurlencod ... and try ..

0
votes

If you want to file uploads with Postman and Laravel, simply remove the Content-Type header setting in Postman.

0
votes

set method as post

enter image description here

and at body ... select the radio that shows url encoded

enter image description here

0
votes

see an image ... click on text set it as flie

enter image description here