49 lines
1.3 KiB
PHP
49 lines
1.3 KiB
PHP
<!-- Generate a Pre-Signed URL (Direct Download Link)
|
|
This is better for web apps — the file is not stored on your server, and the link expires after a set time.
|
|
Php -->
|
|
<?php
|
|
require 'vendor/autoload.php';
|
|
|
|
use Aws\S3\S3Client;
|
|
use Aws\Exception\AwsException;
|
|
|
|
$minioConfig = [
|
|
'version' => 'latest',
|
|
'region' => 'gh-greater-accra-dzen-ayor-home',
|
|
'endpoint' => 'http://192.168.68.152:9201',
|
|
'use_path_style_endpoint' => true,
|
|
'credentials' => [
|
|
'key' => 'c7TpMCcy8txJftPu12Za', // MinIO Access Key
|
|
'secret' => 'NpbiqTjYkUDxUjliOP5fmXaTu6fOSWoKKJXnK1Ev', // MinIO Secret Key
|
|
],
|
|
];
|
|
|
|
$bucketName = 'permituploads';
|
|
$objectKey = 'uploads/Proposed L4L.docx'; // Path inside bucket
|
|
|
|
|
|
try {
|
|
$s3Client = new S3Client($minioConfig);
|
|
|
|
// Create a pre-signed request valid for 1 hour
|
|
$cmd = $s3Client->getCommand('GetObject', [
|
|
'Bucket' => $bucketName,
|
|
'Key' => $objectKey
|
|
]);
|
|
|
|
$request = $s3Client->createPresignedRequest($cmd, '+1 hour');
|
|
|
|
// Get the actual URL
|
|
$presignedUrl = (string) $request->getUri();
|
|
|
|
echo "Pre-signed URL (valid for 1 hour):\n$presignedUrl\n";
|
|
|
|
}
|
|
catch (AwsException $e) {
|
|
echo "SDK Error: " . $e->getMessage();
|
|
}
|
|
catch (Exception $e) {
|
|
echo "Error: " . $e->getMessage();
|
|
}
|
|
|