简体   繁体   中英

Laravel Maatwebsite excel Large file upload fails (The import file failed to upload.)

I am creating a system To upload and save all data from excel/csv sheet to Database. It work fine for small files but whenever I try to upload Large file like 250MB, 500MB files I get an error

The import file failed to upload.

I upgraded My Post Max limit in php.ini file to 1GB. Max Memory Uses, Max Execution Time. But Nothing is working.

Plugin I am using with Laravel is Maatwebsite 3.1

Try set the value of upload_max_filesize and post_max_size in your php.ini :

; Maximum allowed size for uploaded files.

upload_max_filesize = 500M

; Must be greater than or equal to upload_max_filesize

post_max_size = 500M

but it's not recommended, because it can cause server overload.

Try to chunk or batch the import: https://laravel-excel.maatwebsite.nl/3.1/imports/chunk-reading.html

Here is an example from the documentation guide:

namespace App\Imports;

use App\User;
use Maatwebsite\Excel\Concerns\ToModel;
use Maatwebsite\Excel\Concerns\WithChunkReading;

class UsersImport implements ToModel, WithChunkReading
{
    public function model(array $row)
    {
        return new User([
            'name' => $row[0],
        ]);
    }

    public function chunkSize(): int
    {
        return 1000;
    }
}

Set your QUEUE_DRIVER = database in your .env file.

I always got a '504 Timed out' when uploading big excel file. But with 'QUEUE_DRIVER = database' it uploads perfect.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM