DEV Community

Saiks
Saiks

Posted on

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.

Top comments (0)