当前位置:  开发笔记 > 编程语言 > 正文

文件上传到aws S3 Laravel 5.1

如何解决《文件上传到awsS3Laravel5.1》经验,为你挑选了1个好方法。

我收到以下错误:

FilesystemManager.php第179行中的FatalErrorException:未找到类'League\Flysystem\AwsS3v3\AwsS3Adapter'

码:

//Composer.json

    "require": {
            "php": ">=5.5.9",
            "laravel/framework": "5.1.*",
            "laravel/socialite": "~2.0",
            "guzzlehttp/guzzle": "~4.0",
            "predis/predis": "^1.0",
            "tymon/jwt-auth": "0.5.*",
            "league/flysystem-aws-s3-v2": "^1.0"
        },
        "require-dev": {
            "fzaninotto/faker": "~1.4",
            "mockery/mockery": "0.9.*",
            "phpunit/phpunit": "~4.0",
            "phpspec/phpspec": "~2.1"
        }

//config/filesystem.php


    'default' => 's3',
     'cloud' => 's3',
     'disks' => [

            'local' => [
                'driver' => 'local',
                'root'   => storage_path('app'),
            ],

            's3' => [
                'driver' => 's3',
                'key'    => '***********',
                'secret' => '**************************************',
                'region' => '*****',
                'bucket' => '************',
            ],


        ],

//FileController

    namespace App\Http\Controllers;
    use Illuminate\Http\Request;
    use App\Http\Requests;
    use Illuminate\Contracts\Filesystem\Filesystem;
    use App\Http\Controllers\Controller;
    use JWTAuth;
    use Tymon\JWTAuth\Exceptions\JWTException;
    public function postProfilePhoto(Request $request)
        {
            $token=JWTAuth::getToken();
            $user = JWTAuth::toUser($token);
            $image = $request->file('image');
            //return $image;
            $id=$user->id;
            if($image)
            {
            $imageFileName = time() . '.' . $image->getClientOriginalExtension();
            //return $imageFileName;
            $s3 = \Storage::disk('s3');
        $filePath = '/profilePhotos/'.$id . $imageFileName;
        $s3->put($filePath, file_get_contents($image), 'public');

            try{
                ProfilePhoto::create(['userId'=>$id,'imgUrl'=>$filePath]);

                return json_encode(['message'=>'Done!','Id'=>200,'Response'=>'']);
            }
            catch(Exception $e)
            {
                return json_encode(['message'=>'Not Allowed!','Id'=>402,'Response'=>'']);
            }
            }
            else
            {
            return json_encode(['message'=>'No Pic!','Id'=>404,'Response'=>'']);
        }
        }

Marcin Nabia.. 20

您需要先在控制台中运行:

composer remove league/flysystem-aws-s3-v2

然后你需要在控制台中运行:

composer require league/flysystem-aws-s3-v3:~1.0

安装S3文件系统.

Laravel 5.1+ 需要V3版本而不是V2 版本.



1> Marcin Nabia..:

您需要先在控制台中运行:

composer remove league/flysystem-aws-s3-v2

然后你需要在控制台中运行:

composer require league/flysystem-aws-s3-v3:~1.0

安装S3文件系统.

Laravel 5.1+ 需要V3版本而不是V2 版本.

推荐阅读
360691894_8a5c48
这个屌丝很懒,什么也没留下!
DevBox开发工具箱 | 专业的在线开发工具网站    京公网安备 11010802040832号  |  京ICP备19059560号-6
Copyright © 1998 - 2020 DevBox.CN. All Rights Reserved devBox.cn 开发工具箱 版权所有