Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Oracle Cloud Infra File Storage Compatibility #1799

Open
coolgauravjain90 opened this issue Jun 6, 2024 · 4 comments
Open

Oracle Cloud Infra File Storage Compatibility #1799

coolgauravjain90 opened this issue Jun 6, 2024 · 4 comments

Comments

@coolgauravjain90
Copy link

Bug Report

Q A
Flysystem Version 3.0
Adapter Name OCI
Adapter version NA

Summary

How to reproduce

Unable to integrate OCI in laravel 10 with this flysystem.

@olivier1208
Copy link

Finally managed to make it work

You can follow this tutorial but you will have to make some changes in your Provider

As mentionned in the Official Laravel Documentation you need to update the implementation

Here's my working implementation with :

  • Php 8.3
  • Laravel 11
  • league/flysystem-aws-s3-v3 "^3.0" (be sure to composer require league/flysystem-aws-s3-v3 "^3.0" --with-all-dependencies)
<?php

namespace App\Providers;

use Illuminate\Filesystem\FilesystemAdapter;
use Illuminate\Support\ServiceProvider;
use Aws\S3\S3Client;
use League\Flysystem\AwsS3V3\AwsS3V3Adapter;
use League\Flysystem\Filesystem;
use Illuminate\Support\Facades\Storage;

class OciObjectStorageServiceProvider extends ServiceProvider
{
    /**
     * Register services.
     */
    public function register(): void
    {
        //
    }

    public function boot()
    {
        if (config('filesystems.default') !== 'oci') {
            return;
        }

        Storage::extend('s3', function($app, $config) {
            $myConfig = [
                'credentials' => [
                    'key'    => $config['key'],
                    'secret' => $config['secret'],
                ],
                'region' => $config['region'],
                'version' => '2006-03-01',
                'use_path_style_endpoint' => true, // Set to true if you are using an S3 clone
                'bucket_endpoint' => true,
                'endpoint' => $config['url']
            ];
            $client = new S3Client($myConfig);
            $adapter = new AwsS3V3Adapter($client, $config['bucket']);

            return new FilesystemAdapter(
                new Filesystem($adapter, $config),
                $adapter,
                $myConfig
            );
        });
    }
}

You can give such a try in one of your controller (for the sake of the test) :

  Storage::disk('oci')->put('test.txt', 'Hello World');

Enjoy 🚀

@maiconmva
Copy link

Finally managed to make it work

You can follow this tutorial but you will have to make some changes in your Provider

As mentionned in the Official Laravel Documentation you need to update the implementation

Here's my working implementation with :

  • Php 8.3
  • Laravel 11
  • league/flysystem-aws-s3-v3 "^3.0" (be sure to composer require league/flysystem-aws-s3-v3 "^3.0" --with-all-dependencies)
<?php

namespace App\Providers;

use Illuminate\Filesystem\FilesystemAdapter;
use Illuminate\Support\ServiceProvider;
use Aws\S3\S3Client;
use League\Flysystem\AwsS3V3\AwsS3V3Adapter;
use League\Flysystem\Filesystem;
use Illuminate\Support\Facades\Storage;

class OciObjectStorageServiceProvider extends ServiceProvider
{
    /**
     * Register services.
     */
    public function register(): void
    {
        //
    }

    public function boot()
    {
        if (config('filesystems.default') !== 'oci') {
            return;
        }

        Storage::extend('s3', function($app, $config) {
            $myConfig = [
                'credentials' => [
                    'key'    => $config['key'],
                    'secret' => $config['secret'],
                ],
                'region' => $config['region'],
                'version' => '2006-03-01',
                'use_path_style_endpoint' => true, // Set to true if you are using an S3 clone
                'bucket_endpoint' => true,
                'endpoint' => $config['url']
            ];
            $client = new S3Client($myConfig);
            $adapter = new AwsS3V3Adapter($client, $config['bucket']);

            return new FilesystemAdapter(
                new Filesystem($adapter, $config),
                $adapter,
                $myConfig
            );
        });
    }
}

You can give such a try in one of your controller (for the sake of the test) :

  Storage::disk('oci')->put('test.txt', 'Hello World');

Enjoy 🚀

Hello,

Can you show me how is your config OCI file in filesystem.php?

how u set the URL parm?

any way i used has problems..

@maiconmva
Copy link

@olivier1208 Hello,

Can you show me how is your config OCI file in filesystem.php?

how u set the URL parm?

any way i used has problems..

@olivier1208
Copy link

@olivier1208 Hello,

Can you show me how is your config OCI file in filesystem.php?

how u set the URL parm?

any way i used has problems..

As simple as that :

        'oci' => [
            'driver' => 's3',
            'key' => env('OCI_ACCESS_KEY_ID'),
            'secret' => env('OCI_SECRET_ACCESS_KEY'),
            'region' => env('OCI_DEFAULT_REGION'),
            'bucket' => env('OCI_BUCKET'),
            'url' => env('OCI_URL') .  '/'.  env('OCI_BUCKET'),
        ],

Asssumed you have this in your .env :

FILESYSTEM_DISK=oci
OCI_ACCESS_KEY_ID=yout_access_key
OCI_SECRET_ACCESS_KEY=your_secret_key
OCI_DEFAULT_REGION=your_region
OCI_BUCKET=your_bucket
OCI_URL=https://your_namespace.compat.objectstorage.your_region.oraclecloud.com
OCI_USE_PATH_STYLE_ENDPOINT=false

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants