Lumen-framework: Lumen API File Upload is not working

Created on 11 Jan 2018  Â·  7Comments  Â·  Source: laravel/lumen-framework

  • Lumen Version: 5.5.2
  • PHP Version:7.1
  • Database Driver & Version:

Description:

Problem is that , Request object is Returning Null when I am sending , Content-Type: multipart/form-data If I change the Content-Type to application/json is working like a charm, I want to get input file from Api Request . any suggestions??

Steps To Reproduce:

Here is my code I am using Postman to call the service

 if( $request->file('image'))
           {
           $file = $request->file('image')->getClientOriginalName();
           $date = new DateTime();
           $d = $date->format('YmdHms').$file;
           $destinationPath ="images/";
           $request->file('image')->move($destinationPath, $d);
           }
           else 
           {
               $d = '';
           }

         $artistWork = ArtistWork::create([      
            'artist_id' => $request->input('artist_id'),    
            'image'=>$d,
                ]);

All 7 comments

You must set a configuration directive. See below:

upload_tmp_dir (source)

The temporary directory used for storing files when doing file upload. Must be writable by whatever user PHP is running as. If not specified PHP will use the system's default.

If the directory specified here is not writable, PHP falls back to the system default temporary directory. If open_basedir is on, then the system default directory must be allowed for an upload to succeed.

Cheers.

Hey Hakuno,

Thanks for answer.

upload_tmp_dir is already setup and all users have full permissions to access the folder.
still not working.

Hey vickygillsf,

Try dumping the $_FILES superglobal with _var_dump_ and see whats inside.
Check if there is a $_FILES['']['error'] key that could help you.

Also check your php.ini _max_file_uploads_ and see if the file size is not too big.

http://php.net/manual/en/ini.core.php#ini.upload-max-filesize

Hey msolhao,

I think it is a bug, i have deployed services to live server and i am calling services from my Pc its working fine, but when i call the service from someone other's PC , The Resquest Object is POST Null value, i have tried all methods, var_dump(); , print_r() Request Object still getting null from Service.

Thanks,

Closing this issue because it's already solved, old or not relevant anymore. Feel free to reply if you're still experiencing this issue.

thanks to @manfredjb, please check your upload_max_filesize directive in php.ini,

Also check file_uploads directive in php.ini.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jairobjunior picture jairobjunior  Â·  4Comments

jampack picture jampack  Â·  3Comments

soderluk picture soderluk  Â·  3Comments

timrogers picture timrogers  Â·  3Comments

megawubs picture megawubs  Â·  5Comments