简体   繁体   中英

Laravel 5.3 Uploading 52 images with AJAX Error

I have a problem. I'm using Bootstrap fileinput to upload 52 images with async AJAX requests. It uploads 90% of the files and randomly gives errors on few of the images.

This is the error:

SQLSTATE[HY000] [1045] Access denied for user 'forge'@'localhost' (using password: NO)

Upload function:

public function uploadTemp360(Request $request)
{
    $image = $request->file('view360s');
    $fileName = $image->getClientOriginalName().'.'.$image->getClientOriginalExtension();
    $path = public_path().'/uploads/temp/';

    if ($image->isValid()){
        $image->move($path, $fileName);
    }

    return [
        'initialPreview' => [
            "<img  style='height:160px' src='/uploads/temp/".$fileName."' class='file-preview-image'>",
        ],
        'initialPreviewConfig' => [
            ['caption' => $fileName, 'width' => '120px', 'url' => route('admin.products.delete-temp-360'), 'key' => $fileName, 'size' => \File::size($path.$fileName)],
        ],
        'append' => true,
        'filename' => $fileName,
    ];
}

I don't know what's going on and how is it causing DB error by running this code...

I have found in laravel log this error: production.ERROR: exception 'RuntimeException' with message 'The only supported ciphers are AES-128-CBC and AES-256-CBC with the correct key lengths.'

This could be a problem with the Laravel app key. Try executing these two commands in the following order using the command line from your projects root directory:

php artisan key:generate
php artisan config:clear

You can also try making sure that in your config/app.php file you have the following and try to clear the config again:

'cipher' => 'AES-128-CBC',

It seems your database connection is being closed. Using following code you can keep you connection alive after each image upload.

DB::reconnect();

I have fixed that issue with running command: php artisan config:cache . It was problem because of Laravel can't read .env file sometimes...

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