Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

File upload with Laravel through REST

I'm trying to upload videos (i have also tried images) through a REST api in Laravel through Postman.

So far I have tried to do the simplest upload, but nothing seems to work. I'm doing a POST request to http://localhost:8000/api/videos using the "form-data" option in PostMan and setting the "file" option so i can use the "browse" button to find a file on my PC and calling the file "file".

In the controller i'm doing this:

return $request->file('file')->getClientOriginalExtension();

But i get the error "Call to a member function getClientOriginalExtension() on null". I have also tried:

return Input::file('file')->getClientOriginalExtension();

But it's the same result.

Anyone have an idea what i'm doing wrong?

like image 758
bsgrd Avatar asked Jan 04 '23 19:01

bsgrd


1 Answers

Okay, I found out what was wrong. When choosing "form-data" in PostMan, it automatically sets a header "Content-Type: application/x-www-form-urlencoded".

I just removed the header, and everything worked :)

like image 152
bsgrd Avatar answered Jan 07 '23 10:01

bsgrd