Framework: Request $request->file('file') return null when upload files from Angular 4 Component

Created on 23 Oct 2017  路  21Comments  路  Source: laravel/framework

  • Laravel Version: 5.4.
  • PHP Version:5.6
  • Database Driver & Version: mysql

When i use $_FILES it show the data, but when i use $request->file('file') it return null

In Angular 4 there is no need to use multipart/form-data ContentType

I need answers to this
Thankz

Most helpful comment

This is a bug in Laravel because $FILE shows file is there. Is Laravel support REST APIs It should be able to handle file upload as HTTP request. Now both issues have been closed without solution.

All 21 comments

still not working... i add headers.append('Content-Type', 'x-www-form-urlencoded'); to headers

What does it look like in Network tab?

------WebKitFormBoundaryBMkkCBnexJpXEpyP
Content-Disposition: form-data; name="uploadFile"; filename="Customer Credit Report.xlsx"
Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet

------WebKitFormBoundaryBMkkCBnexJpXEpyP--

this is the request payload
now $_FILES not working after i used ('Content-Type', 'x-www-form-urlencoded');

I see you've got uploadFile as the input name but have $request->file('file') as your reading method. They should match.

yes. i used that way.As common name i used file just for the this issue

Please keep your code consistent because I'm looking over it from my point of view.

ok..

This repo is for bug tracking. Use the forums or slack channel for solving your issue

then it is better to stick to the forums. This repo is for bug tracking

@Dylan-DPC is this not a bug? i think it is a bug... this #13457 still going although it closed..

I'm not familiar with Angular 4 upload process, since you're posting an issue on the laravel repository please share steps to replicate using plain code or at least enough information with someone having a fresh laravel app with no angular to replicate :)

Otherwise please use the forums for help.

its easy to close issues by the way @themsaid .Thank you for giving nothing... Its not about Angular 4 its about laravel Request class.. I think I show the request payload. Its contain the file but laravel not get the file. If u do not to fix this just do not comment or close.. So you are doing nothing for to fix this bug..

Thank @bbashy atleast trying to help

@ipula If it's not Angular related, post code to reproduce it using a form. All my uploads work fine.

@ipula try this: https://stackoverflow.com/questions/41750675/angular-file-upload-via-laravel-controller

Problem here is the report is vague in a way we can't really do anything to fix, I'll keep sharing links I found on google hoping it would help you find the issue :)

Instead it'd be better if you do your research online, try to understand what's going on, and then open an issue saying something like:

File uploaded, headers are 1,2,3, expected X but got Y. Now I can open a up a fresh laravel App and try it see if it's something with Laravel or maybe file is too large so it was lost, maybe wrong encoding, etc...

This kind of help I do provide on the forums, but try to keep this space for real bugs so it's easier for us to separate bugs from questions.

Closing an issue doesn't mean I'm not willing to help, it's just me saying this isn't a confirmed bug in the framework :)

look at this #13457 issue even though it closed. still new comments. not for me some others have this issue.. ok. i will look in forums.. i think its time shift to a new language.

@ipula the reason why we have forums is so that you can seek help there instead of clogging this issue board which makes it difficult for us to spot & solve bugs which are caused by the framework.

This is a bug in Laravel because $FILE shows file is there. Is Laravel support REST APIs It should be able to handle file upload as HTTP request. Now both issues have been closed without solution.

Hi, please delete Content-type header while making REST API call in angular... it will automatically create... Please find the attachment for more details.. it will create headers with content type ( Content-Type: multipart/form-data; boundary=----WebKitFormBoundaryzUjwtsgKra12edJv)

angular_header
Angular header

laravel_controller
Laravel controller

php_laravel_issue
POST method

header_file

Was this page helpful?
0 / 5 - 0 ratings

Related issues

klimentLambevski picture klimentLambevski  路  3Comments

Anahkiasen picture Anahkiasen  路  3Comments

PhiloNL picture PhiloNL  路  3Comments

JamborJan picture JamborJan  路  3Comments

digirew picture digirew  路  3Comments