I am trying to upload a photo from my Laravel 5 app to be stored in AWS. I am using the Postman REST client to test. When I upload a photo, the request returns an empty array. Does anyone know why this might be? Here's the code for my Avatar Controller:
class AvatarController extends Controller { public function __construct(AWS $aws) { $this->aws = $aws; } /** * Store a new avatar for a user. * POST northstar.com/users/{id}/avatar */ public function store(User $user, Request $request) { dd($request->all()); // dd($request->file('photo')); $file = $request->file('photo'); // $file = Request::file('photo'); // $file = Input::file('photo'); $v = Validator::make( $request->all(), ['photo' => 'required|image|mimes:jpeg,jpg|max:8000'] ); if($v->fails()) return Response::json(['error' => $v->errors()]); $filename = $this->aws->storeImage('avatars', $file); // Save filename to User model $user->avatar = $filename; $user->save(); // Respond to user with success return response()->json('Photo uploaded!', 200); } }
Found the answer - looks like there was an issue with my headers in Postman. I had both Accept application/json and Content-Type application/json. Once I removed Content-Type, all is fixed. Thanks!
Bit late to the party, but might be usefull for others: My problem was that the Content-Type
header value was application/json
while the actual payload was form data. Changing the header to application/x-www-form-urlencoded
fixed the issue.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With