Created
June 3, 2024 04:23
-
-
Save komputronika/f7d917f4f038b95ac2f0651941b51fe2 to your computer and use it in GitHub Desktop.
Get file from private S3 Bucket (Biznet)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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