This repository has been archived by the owner on Nov 23, 2023. It is now read-only.
/
cs3client.php
executable file
·70 lines (66 loc) · 2.06 KB
/
cs3client.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
<?php
ini_set('error_reporting', E_ALL);
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
require_once 'vendor/autoload.php';
use Aws\S3\S3Client;
use PHPUnit\Framework\TestCase;
class s3test extends TestCase
{
const BUCKET = 'mamery_lane';
const KEY = 'Yin_Yang.jpg';
public function testUrl(): void
{
$content = "body_content";
$s3Client = new S3Client([
'credentials' => [
'key' => 'AccessKeyEXAMPLE',
'secret' => 'TheVeryLongLongLongSecretKeyEXAMPLE',
],
'endpoint' => 'https://hb.bizmrg.com',
'region' => 'ru-msk',
'version' => 'latest',
]);
$res = $s3Client->putObject([
'Key' => self::KEY,
'Bucket' => self::BUCKET,
'Body' => $content,
]);
$cmd = $s3Client->getCommand('GetObject', [
'Bucket' => self::BUCKET,
'Key' => self::KEY,
]);
$request = $s3Client->createPresignedRequest($cmd, '+20 minutes');
// var_dump ($request);
$presignedUrl = (string) $request->getUri();
print($presignedUrl);
$page = file_get_contents($presignedUrl);
print($page);
$this->assertEquals(
$content,
$page
);
}
public function test()
{
$s3Client = new S3Client([
'credentials' => [
'key' => 'wjVNWdZzrWt9EaLuRi2DoT',
'secret' => 'cdWXHsw5ToJpdzpjKXW5AeE9E2Gr1Q25AULKndqcN2f4',
],
'endpoint' => 'https://hb.bizmrg.com',
'region' => 'ru-msk',
'version' => 'latest',
]);
$cmd = $s3Client->getCommand('GetObject', [
'Bucket' => self::BUCKET,
'Key' => self::KEY,
]);
$request = $s3Client->createPresignedRequest($cmd, '+1 minutes');
$presignedUrl = (string) $request->getUri();
return $presignedUrl;
}
}
$test = new s3test();
$url = $test->test();
echo '<img src="'.$url.'" alt="">';