DEV Community

Md. Abdur rahman
Md. Abdur rahman

Posted on • Originally published at dev.to

Render Wasabi Cloud File

Wasabi is a cloud object storage that is compatible with Amazon S3. It can be integrated with AWS, Google Cloud or Microsoft Azure solutions, using the same protocol and tools. Wasabi is a value-oriented, high-performance, low-latency, and high-availability cloud object storage offering.

Generating a pre-signed S3 URL for uploading an object in your application code with AWS SDK for PHP (V2)

  • You can make a helper function like this inside app/Helpers/funtions.php.
if (!function_exists('renderWasabiCloudFile')) {
    function renderWasabiCloudFile($fileLocationInsideYourBucket)
    {
        $s3 = new \Aws\S3\S3Client([
            'endpoint' => config('filesystems.disks.wasabi.endpoint'),
            'region' => config('filesystems.disks.wasabi.region'),
            'version' => 'latest',
            'credentials' => array(
                'key' => config('filesystems.disks.wasabi.key'),
                'secret' => config('filesystems.disks.wasabi.secret'),
            )
        ]);

        $cmd = $s3->getCommand('GetObject', [
            'Bucket' => config('filesystems.disks.wasabi.bucket'),
            'Key' => $fileLocationInsideYourBucket, //hYTYRT56.jpg
            'ACL' => 'public-read',
        ]);

        $request = $s3->createPresignedRequest($cmd, '+20 minutes');

        $fileUrl = (string)$request->getUri();

        return $fileUrl;
    }
}
Enter fullscreen mode Exit fullscreen mode
  • Now, call the function and pass $fileUrl from your db.
<img class="img-fluid" src={{renderWasabiCloudFile($fileUrl)}}> //this url would come from your database (file path url)
Enter fullscreen mode Exit fullscreen mode

You can also follow up the official guidance Generate pre-signed urls to learn more.

Top comments (2)

Collapse
 
marbabu profile image
Md. Abdur rahman

ensure your bucket policy generation properly and wasabi bucket settings permission. its highly recommend for render to give it permission. see, part 1
And while save file into disk don't forget to pass as 'public'. see part 2

Collapse
 
asrandev_0c3a4c0005ed95f6 profile image
Asrandev

not work