How to integrate Object Storage in Laravel?
Here are detailed steps for setting up and using Minio Cluster on AccuWeb.Cloud, integrating it with a Laravel project, and managing file uploads:
Step-by-Step Guide
Step 1: Log in to AccuWeb.Cloud Dashboard
- Navigate to AccuWeb.Cloud: Open your web browser and go to AccuWeb.Cloud.
- Login: Enter your credentials (username and password) to access your AccuWeb.Cloud dashboard.
Step 2: Install Minio Cluster from Marketplace
- Go to Marketplace: Locate and click “Marketplace” in your AccuWeb.Cloud dashboard.
- Search and Install Minio Cluster: In the Marketplace, navigate to “Storage & File” and search for Minio Cluster. Install it following the prompts.
Step 3: Configure Minio Cluster
Configure Minio Cluster: After installation, configure your Minio Cluster by specifying:
- Number of nodes (e.g., 1 node for demo purposes)
- Environment name (e.g., minio-cluster-demo)
- Display name (e.g., Minio Cluster Demo)
- Region (e.g., US)
Step 4: Retrieve Minio Cluster Credentials
Check Email: Check your registered email for Minio Cluster admin panel URL, Access Key, and Secret Key provided after installation.
Step 5: Log in to Minio Cluster
Access Minio Cluster: Login to the Minio Cluster admin panel using the credentials received.
Step 6: Create a Bucket
Create Bucket: Within the Minio Cluster admin panel, create a new bucket for storing files.
Step 7: Access File Storage in Bucket
Upload and View Files: Upload files to your created bucket. Verify successful upload by checking the file list within the bucket.
Step 8: Configure Laravel .env File
Add Minio Credentials: Edit your Laravel project’s .env file to include Minio configuration details:
MINIO_ENDPOINT=your_minio_url
MINIO_ACCESS_KEY=your_access_key
MINIO_SECRET_KEY=your_secret_key
MINIO_BUCKET=your_bucket_name
MINIO_USE_PATH_STYLE_ENDPOINT=true
Replace placeholders (your_minio_url, your_access_key, your_secret_key, your_bucket_name) with your actual Minio Cluster details.
Step 9: Set Filesystem Disk in Laravel
Edit config/filesystems.php: Configure Minio as a filesystem disk in Laravel’s configuration:
'disks' => [
    // Other disks...
    'minio' => [
        'driver' => 's3',
        'endpoint' => env('MINIO_ENDPOINT'),
        'use_path_style_endpoint' => env('MINIO_USE_PATH_STYLE_ENDPOINT', true),
        'key' => env('MINIO_ACCESS_KEY'),
        'secret' => env('MINIO_SECRET_KEY'),
        'region' => 'us-east-1', // Add region if necessary
        'bucket' => env('MINIO_BUCKET'),
        'url' => env('MINIO_ENDPOINT') . '/' . env('MINIO_BUCKET'),
    ],
],
Step 10: Upload Files in Laravel Controller
Controller Code: In your Laravel controller, add a method to handle file uploads to Minio:
public function uploadFile(Request $request)
{
    $file = $request->file('file_name');
    $fileName = $file->getClientOriginalName();
    $path = Storage::disk('minio')->putFile('uploads', $file);
    // Optionally, return the path of the uploaded file
    return response()->json(['path' => $path]);
}
Adjust ‘file_name’ and ‘uploads’ as per your application’s needs.
Step 11: View the Uploaded File in Minio Bucket
Verify File Upload: After uploading a file using your Laravel application, verify that it appears in your Minio bucket.
Step 12: Access File Content in Laravel
Retrieve File Content: Use Laravel’s Storage facade to retrieve and process file contents from Minio:
use Illuminate\Support\Facades\Storage;
public function getFileContent($filePath)
{
    $fileContents = Storage::disk('minio')->get($filePath);
    $image = base64_encode($fileContents);
    $src = 'data:image/jpeg;base64,'.$image;
    // Use $src in your view to display the image or file content
    return view('file.show', compact('src'));
}
$filePath should be the path to the file in your Minio bucket.






