0

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.

Lakhwinder Singh
  • 5,536
  • 5
  • 27
  • 52

4 Answers4

0

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

Masih Ansari
  • 467
  • 3
  • 9
  • if i change the option from form data to w-xxx-formurlencod, how can i browse file from location? –  Jan 07 '19 at 10:10
0

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

  • i wont set any header –  Jan 07 '19 at 10:04
  • @SikhaA: Please check this [link](https://stackoverflow.com/questions/46633582/laravel-file-upload-api-using-postman) –  Jan 07 '19 at 10:06
0

set method as post

enter image description here

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

enter image description here

Masih Ansari
  • 467
  • 3
  • 9
0

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

enter image description here

Masih Ansari
  • 467
  • 3
  • 9