0
votes

I am writing an application in Lumen, to provide APIs to the frontend framework. I am struggling with file upload to S3. Steps I followed.

  • Configured .env file with

AWS_ACCESS_KEY_ID=AKXXXXXXXXXXXXXXXXXX AWS_SECRET_ACCESS_KEY=nXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX AWS_DEFAULT_REGION=me-south-1 AWS_BUCKET=your_bucket_name AWS_URL=https://apigateway.me-south-1.amazonaws.com

  • Using composer installed AWS SDK for Laravel

    composer require aws/aws-sdk-php-laravel:~3.0

  • Now wrote the function like this

    public function upload(Request $request)
    {
        $image = $request->file('image');
        $imageFileName = time() . '.' . $image->getClientOriginalExtension();
        $s3 = Storage::disk('s3');
        $filePath = '/venue/' . $imageFileName;
        $s3->put($filePath, file_get_contents($image));
        return response()->json(['status' => true, 'data' => $imageFileName], Response::HTTP_OK);
    }
    

It would be really great if someone can share an article or full tutorial on how to do this.

1
Thanks @NiravBhoi, here I am using Lumen, so it would be okay? - Muhammed Shihabudeen Labba A
Yes It will be because lumen is child of laravel. But create backup first. - Nirav Bhoi
I know, but some of the features are not available in Lumen. Anyway, I will try with the package you mentioned. - Muhammed Shihabudeen Labba A

1 Answers

0
votes

You need the this dependency:

composer require --with-all-dependencies league/flysystem-aws-s3-v3 "^1.0"

see: https://laravel.com/docs/8.x/filesystem