From 6899adfbfa7fd651841c57cb2dbb22a1d6e755d7 Mon Sep 17 00:00:00 2001 From: saeid_01 Date: Mon, 6 Apr 2020 12:02:07 +0430 Subject: [PATCH] feat: file upload with s3 --- app/Providers/MinIOStorageServiceProvider.php | 49 +++++ composer.json | 1 + composer.lock | 195 +++++++++++++++++- config/app.php | 1 + config/filesystems.php | 11 +- config/medialibrary.php | 4 +- 6 files changed, 252 insertions(+), 9 deletions(-) create mode 100644 app/Providers/MinIOStorageServiceProvider.php diff --git a/app/Providers/MinIOStorageServiceProvider.php b/app/Providers/MinIOStorageServiceProvider.php new file mode 100644 index 0000000..5408922 --- /dev/null +++ b/app/Providers/MinIOStorageServiceProvider.php @@ -0,0 +1,49 @@ + [ + 'key' => $config["key"], + 'secret' => $config["secret"] + ], + 'region' => $config["region"], + 'version' => "latest", + 'bucket_endpoint' => false, + 'use_path_style_endpoint' => true, + 'endpoint' => $config["endpoint"], + ]); + $options = [ + 'override_visibility_on_copy' => true + ]; + return new Filesystem(new AwsS3Adapter($client, $config["bucket"], '', $options)); + }); + } + + /** + * Register the application services. + * + * @return void + */ + public function register() + { + + } +} diff --git a/composer.json b/composer.json index 842930f..adb1df0 100644 --- a/composer.json +++ b/composer.json @@ -9,6 +9,7 @@ "license": "MIT", "require": { "php": "^7.2", + "coraxster/flysystem-aws-s3-v3-minio": "^1.0", "fideloper/proxy": "^4.0", "kalnoy/nestedset": "^5.0", "laravel/framework": "^6.2", diff --git a/composer.lock b/composer.lock index 371a1fa..c89c3e6 100644 --- a/composer.lock +++ b/composer.lock @@ -4,8 +4,139 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "777479d5f72d40de0d12142c590eb01f", + "content-hash": "c41e87ebe57c9f47a0c594757501d667", "packages": [ + { + "name": "aws/aws-sdk-php", + "version": "3.134.3", + "source": { + "type": "git", + "url": "https://github.com/aws/aws-sdk-php.git", + "reference": "3de2711a47e7c3f5e93a5c83f019188fd23f852f" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/aws/aws-sdk-php/zipball/3de2711a47e7c3f5e93a5c83f019188fd23f852f", + "reference": "3de2711a47e7c3f5e93a5c83f019188fd23f852f", + "shasum": "" + }, + "require": { + "ext-json": "*", + "ext-pcre": "*", + "ext-simplexml": "*", + "guzzlehttp/guzzle": "^5.3.3|^6.2.1|^7.0", + "guzzlehttp/promises": "^1.0", + "guzzlehttp/psr7": "^1.4.1", + "mtdowling/jmespath.php": "^2.5", + "php": ">=5.5" + }, + "require-dev": { + "andrewsville/php-token-reflection": "^1.4", + "aws/aws-php-sns-message-validator": "~1.0", + "behat/behat": "~3.0", + "doctrine/cache": "~1.4", + "ext-dom": "*", + "ext-openssl": "*", + "ext-pcntl": "*", + "ext-sockets": "*", + "nette/neon": "^2.3", + "phpunit/phpunit": "^4.8.35|^5.4.3", + "psr/cache": "^1.0", + "psr/simple-cache": "^1.0", + "sebastian/comparator": "^1.2.3" + }, + "suggest": { + "aws/aws-php-sns-message-validator": "To validate incoming SNS notifications", + "doctrine/cache": "To use the DoctrineCacheAdapter", + "ext-curl": "To send requests using cURL", + "ext-openssl": "Allows working with CloudFront private distributions and verifying received SNS messages", + "ext-sockets": "To use client-side monitoring" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "3.0-dev" + } + }, + "autoload": { + "psr-4": { + "Aws\\": "src/" + }, + "files": [ + "src/functions.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "Apache-2.0" + ], + "authors": [ + { + "name": "Amazon Web Services", + "homepage": "http://aws.amazon.com" + } + ], + "description": "AWS SDK for PHP - Use Amazon Web Services in your PHP project", + "homepage": "http://aws.amazon.com/sdkforphp", + "keywords": [ + "amazon", + "aws", + "cloud", + "dynamodb", + "ec2", + "glacier", + "s3", + "sdk" + ], + "time": "2020-04-03T18:11:51+00:00" + }, + { + "name": "coraxster/flysystem-aws-s3-v3-minio", + "version": "1.0.16", + "source": { + "type": "git", + "url": "https://github.com/coraxster/flysystem-aws-s3-v3-minio.git", + "reference": "963b771021be0eda570064a2a5051e1192c3afbd" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/coraxster/flysystem-aws-s3-v3-minio/zipball/963b771021be0eda570064a2a5051e1192c3afbd", + "reference": "963b771021be0eda570064a2a5051e1192c3afbd", + "shasum": "" + }, + "require": { + "aws/aws-sdk-php": "^3.0.0", + "league/flysystem": "^1.0.40", + "php": ">=5.5.0" + }, + "require-dev": { + "henrikbjorn/phpspec-code-coverage": "~1.0.1", + "phpspec/phpspec": "^2.0.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0-dev" + } + }, + "autoload": { + "psr-4": { + "League\\Flysystem\\AwsS3v3\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Frank de Jonge", + "email": "info@frenky.net" + } + ], + "description": "Flysystem adapter for the AWS S3 SDK v3.x, forked for minio support", + "time": "2017-09-26T08:08:44+00:00" + }, { "name": "defuse/php-encryption", "version": "v2.2.1", @@ -810,6 +941,7 @@ "email": "jakub.onderka@gmail.com" } ], + "abandoned": "php-parallel-lint/php-console-color", "time": "2018-09-29T17:23:10+00:00" }, { @@ -856,6 +988,7 @@ } ], "description": "Highlight PHP code in terminal", + "abandoned": "php-parallel-lint/php-console-highlighter", "time": "2018-09-29T18:48:56+00:00" }, { @@ -1387,6 +1520,7 @@ "markdown", "table" ], + "abandoned": "league/commonmark", "time": "2019-09-26T13:28:33+00:00" }, { @@ -1803,6 +1937,63 @@ ], "time": "2019-12-20T14:22:59+00:00" }, + { + "name": "mtdowling/jmespath.php", + "version": "2.5.0", + "source": { + "type": "git", + "url": "https://github.com/jmespath/jmespath.php.git", + "reference": "52168cb9472de06979613d365c7f1ab8798be895" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/jmespath/jmespath.php/zipball/52168cb9472de06979613d365c7f1ab8798be895", + "reference": "52168cb9472de06979613d365c7f1ab8798be895", + "shasum": "" + }, + "require": { + "php": ">=5.4.0", + "symfony/polyfill-mbstring": "^1.4" + }, + "require-dev": { + "composer/xdebug-handler": "^1.2", + "phpunit/phpunit": "^4.8.36|^7.5.15" + }, + "bin": [ + "bin/jp.php" + ], + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.5-dev" + } + }, + "autoload": { + "psr-4": { + "JmesPath\\": "src/" + }, + "files": [ + "src/JmesPath.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Michael Dowling", + "email": "mtdowling@gmail.com", + "homepage": "https://github.com/mtdowling" + } + ], + "description": "Declaratively specify how to extract elements from a JSON document", + "keywords": [ + "json", + "jsonpath" + ], + "time": "2019-12-30T18:03:34+00:00" + }, { "name": "myclabs/php-enum", "version": "1.7.2", @@ -4877,7 +5068,7 @@ "dist": { "type": "path", "url": "./modules/wm-reservation", - "reference": "fb7569ddb3cb6ad614a2f3d68613a8f5a6a4159b" + "reference": "3aa36f2cefdf73b5ecab07f62b194e3a1d03a0f8" }, "require": { "php": "^7.1.3", diff --git a/config/app.php b/config/app.php index 37abb4f..10acaf2 100644 --- a/config/app.php +++ b/config/app.php @@ -175,6 +175,7 @@ return [ App\Providers\EventServiceProvider::class, App\Providers\RouteServiceProvider::class, // App\CorePackages\Authenticate\AthenticateServiceProvider::class, + App\Providers\MinIOStorageServiceProvider::class ], diff --git a/config/filesystems.php b/config/filesystems.php index 1ce0d5f..01c7684 100644 --- a/config/filesystems.php +++ b/config/filesystems.php @@ -70,11 +70,12 @@ return [ ], 'media' => [ - 'driver' => 'ftp', - 'host' => '185.142.158.22', - 'username' => 'willacdn', - 'password' => 'F9NvDsT*HVhLA@$', - 'root' => 'private_html', + 'driver' => 'minio', + 'key' => env('MINIO_KEY', 'your minio server key'), + 'secret' => env('MINIO_SECRET', 'your minio server secret'), + 'region' => 'us-east-1', + 'bucket' => env('MINIO_BUCKET','your minio bucket name'), + 'endpoint' => env('MINIO_ENDPOINT','http://localhost:8000') ], ], diff --git a/config/medialibrary.php b/config/medialibrary.php index 4a2dddb..7bf79a1 100644 --- a/config/medialibrary.php +++ b/config/medialibrary.php @@ -29,7 +29,7 @@ return [ /* * The domain that should be prepended when generating urls. */ - 'domain' => 'https://' . env('AWS_BUCKET') . '.s3.amazonaws.com', + 'domain' => 'https://cdn.willamall.com/' . env('MINIO_BUCKET') , ], 'remote' => [ @@ -74,7 +74,7 @@ return [ * When urls to files get generated, this class will be called. Leave empty * if your files are stored locally above the site root or on s3. */ - 'url_generator' => env('MEDIA_DISK', 'media') != 'media' ? null : 'WM\Common\Services\Media\UrlGenerator\FtpUrlGenerator', + 'url_generator' => env('MEDIA_DISK', 'media') != 'media' ? null : 'WM\Common\Services\Media\UrlGenerator\S3UrlGenerator', /* * Whether to activate versioning when urls to files get generated.