How to Use Pre-Signed URL in PHP with Stook
Generate and use pre-signed URLs in PHP for accessing objects in Medianova Stook Object Storage.
You can generate pre-signed URLs with the AWS SDK for PHP to securely access or share objects stored in Medianova Stook Object Storage. Pre-signed URLs allow time-limited access without exposing your credentials.
Prerequisites
PHP installed on your system
AWS SDK for PHP included in your project
Medianova Stook credentials (Access Key, Secret Key, Endpoint)
Example: Generate a Pre-Signed URL
require 'vendor/autoload.php';
use Aws\S3\S3Client;
use Aws\S3\Exception\S3Exception;
$bucket = "bucket";
$key = "mykey";
// Create a S3Client
$s3 = new Aws\S3\S3Client([
'endpoint' => 'https://customername.mncdn.com',
'profile' => 'medianova',
'version' => 'latest',
'region' => 'us-east-1',
'use_path_style_endpoint' => true
]);
$cmd = $s3->getCommand('GetObject', [
'Bucket' => $bucket,
'Key' => $key,
]);
$request = $s3->createPresignedRequest($cmd, '+20 minutes');
$presignedUrl = (string) $request->getUri();
echo $presignedUrl;
How It Works
Define your bucket and object key.
Create an S3Client with your Stook endpoint and credentials.
Use the
getCommand
method to specify the operation (e.g.,GetObject
).Generate a pre-signed URL with
createPresignedRequest
.Share or use the generated URL to access the object for a limited time.
Troubleshooting / FAQ
Expired URL: Check the validity time (
+20 minutes
,+1 hour
, etc.).Access denied: Verify bucket policy and Stook credentials.
Invalid endpoint: Ensure your Stook endpoint matches your account.
References
Last updated
Was this helpful?