Uploading a large file in laravel 8 returns an empty file with application/octet-stream mimeType

Viewed 240

Am trying to upload images in laravel 8 but for large files this fails.

In my controller i have the following

    public function uploadTemporaryFile(Request $request)
     {
         $request->validate([
           'image' => 'required|mimes:png,jpeg,jpg',
         ])
         $file = $request->file('image');

         //do more stuff here

      }

The above works for smaller image files but large image files 8MB validation fails. After a bit of troubleshooting and logging the $request on large files i found this to be

var_dump($request);

 array (
 'image' => 
   Illuminate\Http\UploadedFile::__set_state(array(
    'test' => false,
    'originalName' => 'IMG_20201203_072650.jpg',
    'mimeType' => 'application/octet-stream',
    'error' => 1,
    'hashName' => NULL,
   )),
  )  

As per above the large image file the mime type seems to change from image/jpeg to application/octet-stream. The same code used to upload small images is used to upload large image files. With the application/octet-stream the $request->file("image") is now empty. How can i get the uploaded file for saving when its a large image file. Or what am i missing.

I have also adjusted both upload_max_filesize and post_max_size to 100M each.

1 Answers
upload_max_filesize
post_max_size

Just put a large value (bigger than the files to be uploaded) on these variables at php.ini.

OBS: modify the correct php.ini file, (FPM, Nginx, Apache, CLI, and correct PHP version), and restart your webserver/fpm. To confirm that you've changed the right file, run:

phpinfo(); 

And look for those values.

Related