DEV Community

Saiks
Saiks

Posted on

4 2

Configure Alibaba Cloud OSS On Laravel Filesystem

Object Storage Service (OSS) is an object storage service by Alibaba Cloud (Aliyun/Ali Cloud), much similar to Amazon Simple Storage Service (Amazon S3). Flysystem integration in Laravel allows easy use of local filesystems, Amazon S3, and Rackspace Cloud Storage.

Although Laravel Docs doesn't mention of Alibaba Cloud OSS, OSS compatibility with S3 API allows you to access it using the same API, without using any additional package or SDK. For information regarding S3 to OSS data migration, and compatible S3 APIs, refer to their documentation.

Laravel Configuration

To use OSS on Laravel, add the following into the disks array in your config/filesystems.php:

        'oss' => [
            'driver' => 's3',
            'key' => env('OSS_ACCESS_KEY_ID'),
            'secret' => env('OSS_SECRET_ACCESS_KEY'),
            'region' => env('OSS_REGION'),
            'bucket' => env('OSS_BUCKET'),
            'endpoint' => env('OSS_ENDPOINT'),
            'url' => env('OSS_URL'),
            'visibility' => 'public', // Default visibility
        ],

Add your Access Key and bucket details for OSS in your .env:

OSS_ACCESS_KEY_ID=EXAMPLE
OSS_SECRET_ACCESS_KEY=Example123
OSS_REGION=oss-ap-southeast-3
OSS_BUCKET=examplebucket
OSS_ENDPOINT=https://oss-ap-southeast-3.aliyuncs.com
OSS_URL=https://oss.example.com

Simple as that! To make OSS your default filesystem disk, set FILESYSTEM_DRIVER and FILESYSTEM_CLOUD to oss in .env. You may also bind your own domain to the bucket to access objects through the domain URL.

AWS Q Developer image

Your AI Code Assistant

Generate and update README files, create data-flow diagrams, and keep your project fully documented. Built to handle large projects, Amazon Q Developer works alongside you from idea to production code.

Get started free in your IDE

Top comments (0)

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay