Question

How to generate presigned URL DO Spaces in Laravel

Hi!

really excited to try digital ocean spaces! I’m currently using Laravel and aws s3 for streaming and download video on my site i’m using aws-sdk-php-laravel right now for generating presigned url for my videos (not the phpleague flysystem)

my question is, how can do this with digitalocean spaces, or rather how can i easily move to do spaces using the same sdk?


Submit an answer

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.

Spaces was designed to be inter-operable with the S3 API (for more details see here). This includes the ability to presign URLs. The only difference when porting from a code base originally targeting S3 will be configuring the correct endpoint (e.g. $REGION.digitaloceanspaces.com).

Here’s a quick example with vanilla PHP:

<?php

// Included aws/aws-sdk-php via Composer's autoloader
// Installed with: composer.phar require aws/aws-sdk-php
require 'vendor/autoload.php';
use Aws\S3\S3Client;

// Configure a client using Spaces
$client = new Aws\S3\S3Client([
        'version' => 'latest',
        'region'  => 'nyc3',
        'endpoint' => 'https://nyc3.digitaloceanspaces.com',
        'credentials' => [
                'key'    => 'MY_SPACES_KEY',
                'secret' => 'MY_SPACES_SECRET,
            ],
]);

$cmd = $client->getCommand('GetObject', [
    'Bucket' => 'examplebucket',
    'Key'    => 'file.ext'
]);

$request = $client->createPresignedRequest($cmd, '+5 minutes');
$presignedUrl = (string) $request->getUri();

echo $presignedUrl;