
Laravel REST API can't handle file
Let me sharing to you about my experience when i create Rest API using Laravel.
Yeah, i was create Rest API like CRUD operation using Laravel. Everything work properly till i need handle/catch some file from Rest API for editing data.
Yeah you know. Normally when create some endpoint for editing data we use PUT or PATCH route method and i need to use form-data for send file.
Then i create validation for validate file image that coming from request in my controller file.
There don't get some file, i have been debugging for several hours for solve it.
Reference
Finally i got some article/issue in github maybe, i have been forgot. Maybe you can chek here or here.
Problem
There, i got some root problem why it cannot catch the file. Yups, the problem is coming from symfony that can't parse data if it's coming from multipart/form-data.
The solution
You can get the solution when you read here.
There, the solution is you can try using x-www-form-urlencoded content disposition.
But, i have other alternative way for my problem. Why we couldn't use POST route method. Yeah just change your PUT route method before to be POST.
That's the way i have been choose.
I hope with this article, some people can save several hours to get the solution when try to solve this.
Sorry about my english quality.