Code Monkey home page Code Monkey logo

nzos3awsbundle's Introduction

NzoS3AwsBundle

Build Status Latest Stable Version

The NzoS3AwsBundle is a Symfony Bundle used to handle AWS S3 Files Upload.

Compatible with Symfony >= 4.4

Installation

Through Composer:

$ composer require nzo/s3-aws-bundle

Register the bundle in config/bundles.php (without Flex):

// config/bundles.php

return [
    // ...
    Nzo\S3AwsBundle\NzoS3AwsBundle::class => ['all' => true],
];

Configure your application's config.yml:

# config/packages/nzo_s3_aws.yaml

nzo_s3_aws:
    aws_access_key: '%env(AWS_ACCESS_KEY)%'  required: 
    aws_secret:     '%env(AWS_SECRET)%'      required: 
    aws_region:     '%env(AWS_REGION)%'      required:  (example: eu-west-1)
    aws_bucket:     '%env(AWS_BUCKET)%'      required:  (the bucket name)
    aws_endpoint:   '%env(AWS_ENDPOINT)%'    optional:

Usage

use Nzo\S3AwsBundle\S3\S3AwsHandler;
    
    private $s3AwsHandler;

    public function __construct(S3AwsHandler $s3AwsHandler)
    {
        $this->s3AwsHandler = $s3AwsHandler;
        
        // without autowiring use: $this->get('nzo_s3_aws')
    }

    public function uploadFilesToS3Aws(string $key, string $filePath)
    {
        try {

            // $key: it represent the file name and path in the S3 Bucket. Example: "my_folder/my-image.jpg"
            // $filePath: is the absolute path to the file. Example: "/var/www/my-image.jpg"

            $awsResult = $this->s3AwsHandler->uploadFile($key, $filePath);


            // Public ACL (default 'private')
            $acl = 'public-read';
            $awsResult = $this->s3AwsHandler->uploadFile($key, $filePath, $acl);

        } catch (\Exception $e) {
            // Unable to upload the file to AWS S3
        }
    }

License

This bundle is under the MIT license. See the complete license in the bundle:

See LICENSE

nzos3awsbundle's People

Contributors

nayzo avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.