Skip to content

Instantly share code, notes, and snippets.

@komputronika
Created June 3, 2024 04:23
Show Gist options
  • Save komputronika/f7d917f4f038b95ac2f0651941b51fe2 to your computer and use it in GitHub Desktop.
Save komputronika/f7d917f4f038b95ac2f0651941b51fe2 to your computer and use it in GitHub Desktop.
Get file from private S3 Bucket (Biznet)
<?php
use Aws\S3\S3Client;
use Aws\S3\Exception\S3Exception;
$key = "myfolder/myfile.ext";
$client = new S3Client([
"version" => "latest",
"region" => getenv("BIZ_ACCESS_REGION"),
"endpoint" => "https://" . getenv("BIZ_ENDPOINT"),
"credentials" => [
"key" => getenv("BIZ_ACCESS_KEY_ID"),
"secret" => getenv("BIZ_ACCESS_KEY_SECRET"),
],
]);
$result = $client->getObject([
"Bucket" => getenv("BIZ_BUCKET_NAME"),
"Key" => $key,
]);
$body = $result->get("Body");
$body->rewind();
// Add http header here, for example:
// header('Content-Type: application/pdf');
// header('Content-Disposition: inline; filename="mydoc.pdf"');
echo $body;
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment