s3client php,Thinkphp用Aws.S3的Sdk实现Minio对象存储链接API

PHP用Aws的SDK实现Minio对象存储链接API

用 thinkphp 框架

通过composer 安装 aws的php版本sdk

cd到thinkphp框架的根目录下,同composer.json目录。

composer require aws/aws-sdk-php

然后新建一个 controller,就可以直接引入Aws的SDK类和函数进行测试

链接本地的 Minio服务器http://192.168.1.112:9005<?php

namespace app\controller;

use app\BaseController;

use Aws\Credentials\Credentials;

use Aws\Endpoint\EndpointProvider;

use Aws\EndpointDiscovery\EndpointList;

use Aws\s3\S3Client;

class Aws extends BaseController{

public function index(){

$credentials =  new Credentials('minioadmin', 'minioadmin');

$s3 = new S3Client([

'version'=> 'latest',

'region' => 'us-east-1',

'endpoint'=> 'http://192.168.1.112:9005',

'credentials'=> $credentials,

'use_path_style_endpoint' => true,

]);

$insert = $s3->putObject([

'Bucket' => 'f202101',

'Key'    => 'testkey'. time().".jpg",

'SourceFile' => 'timgbu.jpg',

]);

// Download the contents of the object.

$retrive = $s3->getObject([

'Bucket' => 'f202101',

'Key'    => '2020春节放假通知.jpg',

]);

$command = $s3->getCommand('GetObject', [

'Bucket' => 'f202101',

'Key'    => '2020春节放假通知.jpg'

]);

// Create a pre-signed URL for a request with duration of 10 miniutes

$presignedRequest = $s3->createPresignedRequest($command, '+10 minutes');

// Get the actual presigned-url

$presignedUrl =  (string)  $presignedRequest->getUri();

$url = $retrive['@metadata']['effectiveUri'];

// Print the body of the result by indexing into the result object.

// 获取所有的buckets;

echo "当前所有存储桶:
";

$buckets = $s3 ->listBuckets();

foreach($buckets['Buckets'] as $bucket){

echo $bucket['Name']. "
";

}

        return "";

}

}

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值