0

I have a decoupled VueJS frontend and a Laravel API backend. When I upload a large file (3GB for instance) there's a Eloquent create() method that doesn't get executed. However, when I upload smaller files (a few hundred MB) it executes without problem.

My code:

public function store(Request $request){
    if(count($request->file('files'))){
        $shareId = substr(md5(rand()), 0, 7);
        try{
            $user = User::where('name', 'Anon')->first();   //save file anonymously
            $upload = $user->uploads()->create(['share_id' => $shareId, 'visibility' => 'public']);
            foreach($request->file('files') as $file){
                \Log::info('before file store');
                $disk = Storage::disk('files');
                $disk->put($file->getClientOriginalName(), fopen($file, 'r+'));
                \Log::info('after file 
                \Log::info('before db create');

                //the below code and everything after it doesn't execute
                $upload->files()->create(['name' => 'testname', 
                    'originalName' => $file->getClientOriginalName(), 
                    'size' => $file->getClientSize(),
                    'path' => 'test', 'visibility' => 'public', 
                    'type' => $file->getClientOriginalExtension()]);
                    \Log::info('after db create');
            }
            return response()->json([
                "success" => $shareId
            ]);
        }
        catch(\Exception $e){
            return response()->json([
                "error" => $e
            ]);
        }
    }
}

I log some text to see what executes and only the below logs are shown:

[2019-09-27 14:15:52] local.INFO: before file store  
[2019-09-27 14:15:52] local.INFO: after file store  
[2019-09-27 14:15:52] local.INFO: before db create  

What is causing this? My PHP server is configured to allow files of up to 5GB to be uploaded. I've also set my max_execution_time to 10mins to test and the problem persists. I've omitted the Vue code as I believe this is a backend issue.

user931018
  • 643
  • 1
  • 10
  • 24
  • `fopen($file, 'r+')`? Do you have 64 GB of ram? – Salim Djerbouh Sep 27 '19 at 15:23
  • @CaddyDZ Could you elaborate? – user931018 Sep 27 '19 at 15:42
  • [fopen()](https://www.php.net/manual/en/function.fopen.php) read the file into memory stream buffer, large files will fail to allocate memory – Salim Djerbouh Sep 27 '19 at 15:44
  • @CaddyDZ The `fopen()` is based off of this question's answer. According to it `fopen()` uses a small amount of RAM? https://stackoverflow.com/questions/36600197/how-to-upload-large-file-5mb-in-laravel-5 Previously I used `$file->store('files');` but it produced the same problem – user931018 Sep 27 '19 at 15:47

0 Answers0