Setting Up Laravel Storage with IDCloudHost Object Storage
As your Laravel application grows, local storage might become insufficient. IDCloud’s Object Storage provides a reliable cloud storage solution. In this article, we’ll dive into integrating it into your Laravel project.
You can try IDCloudHost Object Storage from this link https://console.idcloudhost.com/referral/hw0rs8r
Step 1: Install Required Package
Ensure you have the necessary AWS package installed through Composer as many platforms, including IDCloud, follow AWS SDK standards:
composer require league/flysystem-aws-s3-v3
Step 2: Configure .env
File
Add your IDCloud Object Storage details to your .env
:
AWS_ACCESS_KEY_ID=your_key
AWS_SECRET_ACCESS_KEY=your_secret
AWS_DEFAULT_REGION=your_region
AWS_BUCKET=your_bucket
AWS_USE_PATH_STYLE_ENDPOINT=false
AWS_ENDPOINT=https://is3.cloudhost.id
Replace the above placeholders with your IDCloud credentials
Note : for Indonesia, you can try this region SouthJkt-a.
Step 3: Update config/filesystems.php
Open config/filesystems.php
and add the IDCloud driver to the disks array or you can set like S3 (Default Config):
's3' => [
'driver' => 's3',
'key' => env('AWS_ACCESS_KEY_ID'),
'secret' => env('AWS_SECRET_ACCESS_KEY'),
'region' => env('AWS_DEFAULT_REGION'),
'bucket' => env('AWS_BUCKET'),
'url' => env('AWS_URL'),
'endpoint' => env('AWS_ENDPOINT'),
'use_path_style_endpoint' => env('AWS_USE_PATH_STYLE_ENDPOINT', false),
],
Step 4: Utilizing IDCloud Storage
With the above configuration, you can seamlessly use IDCloud storage in your code:
use Illuminate\Support\Facades\Storage;
// Upload a file to IDCloud
Storage::disk('s3')->put('filename.jpg', $fileContent);// Retrieve a file from IDCloud
$file = Storage::disk('s3')->get('filename.jpg');
Additional Tips
- Never hardcode your IDCloud credentials in your code. Always use environment variables (
.env
) for this purpose. - Always ensure that your IDCloud bucket permissions are set appropriately to avoid unintentional data exposure.