There is a problem downloading files using Laravel on the back-end.
Question
The Laravel $request->file() method returns null.
Customization
I am creating an AJAX request using superagent , debugging the request and everything seems fine. Content-Length changes depending on the image being added, indicating that the image has been added to the request. The Content-Type parameter is also set to multipart/form-data .
// request headers Content-Length:978599 Content-Type:multipart/form-data; // request payload Content-Disposition: form-data; name="files"; filename="item-keymoment.png" Content-Type: image/png
But I can not get the file in Laravel. Using $request->file('files') returns NULL , but if I debug the $_FILES , I noticed that my file was uploaded.
dd($request->file('files')) // NULL dd($_FILES); // array:1 [ // "files" => array:5 [ // "name" => "item-keymoment.png" // "type" => "image/png" // "tmp_name" => "/tmp/phpipbeeM" // "error" => 0 // "size" => 978274 // ] // ] dd($request->files->all()) // []
What can cause Laravel to ignore the file?
Content-Type input file is not application/octet-stream ?
Below are the answers to the question.
source share