使用 minio 搭建私有对象存储云。aws-php-sdk 操作object
How to use AWS SDK for PHP with Minio Server
aws-sdk-php is the official AWS SDK for the PHP programming language. In this recipe we will learn how to use aws-sdk-php with Minio server.
1. Prerequisites
Install Minio Server from here.
2. Installation
Install aws-sdk-php from AWS SDK for PHP official docs here.
3. Use GetObject and PutObject
Example below shows putObject and getObject operations on Minio server using aws-sdk-php. Please replace endpoint,key, secret, Bucket with your local setup in this example.php file. Note that we set use_path_style_endpoint to true to use Minio with AWS SDK for PHP. Read more in the AWS SDK for PHP docs here.
Copy<?php
// Include the SDK using the Composer autoloader
date_default_timezone_set('America/Los_Angeles');
require 'vendor/autoload.php';
$s3 = new Aws\S3\S3Client([
'version' => 'latest',
'region' => 'us-east-1',
'endpoint' => 'http://localhost:9000',
'use_path_style_endpoint' => true,
'credentials' => [
'key' => 'YOUR-ACCESSKEYID',
'secret' => 'YOUR-SECRETACCESSKEY',
],
]);
// Send a PutObject request and get the result object.
$insert = $s3->putObject([
'Bucket' => 'testbucket',
'Key' => 'testkey',
'Body' => 'Hello from Minio!!'
]);
// Download the contents of the object.
$retrive = $s3->getObject([
'Bucket' => 'testbucket',
'Key' => 'testkey',
'SaveAs' => 'testkey_local'
]);
// Print the body of the result by indexing into the result object.
echo $retrive['Body'];
After the file is updated, run the program
Copyphp example.php
Hello from Minio!!
4. Create a pre-signed URL
Copy<?php
// Get a command object from the client
$command = $s3->getCommand('GetObject', [
'Bucket' => 'testbucket',
'Key' => 'testkey'
]);
// 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();
5. Get a plain URL
To get a plain URL, you'll need to make your object/bucket accessible with public permission. Also, note that you'll not get the URL with X-Amz-Algorithm=[...]&X-Amz-Credential=[...]&X-Amz-Date=[...]&X-Amz-Expires=[...]&X-Amz-SignedHeaders=[...]&X-Amz-Signature=[...]
Copy<?php
$plainUrl = $s3->getObjectUrl('testbucket', 'testkey');
6. Set a Bucket Policy
Copy<?php
$bucket = 'testbucket';
// This policy sets the bucket to read only
$policyReadOnly = '{
"Version": "2012-10-17",
"Statement": [
{
"Action": [
"s3:GetBucketLocation",
"s3:ListBucket"
],
"Effect": "Allow",
"Principal": {
"AWS": [
"*"
]
},
"Resource": [
"arn:aws:s3:::%s"
],
"Sid": ""
},
{
"Action": [
"s3:GetObject"
],
"Effect": "Allow",
"Principal": {
"AWS": [
"*"
]
},
"Resource": [
"arn:aws:s3:::%s/*"
],
"Sid": ""
}
]
}
';
// If you want to put it on a specific folder you just change 'arn:aws:s3:::%s/*' to 'arn:aws:s3:::%s/folder/*'
// Create a bucket
$result = $s3->createBucket([
'Bucket' => $bucket,
]);
// Configure the policy
$s3->putBucketPolicy([
'Bucket' => $bucket,
'Policy' => sprintf($policyReadOnly, $bucket, $bucket),
]);
获取对象的方法:
$result = $client->getObject(array(
'Bucket' => '123124',
'Key' => '2018022610202562513.jpeg',
'ResponseContentType' => 'image/jpeg',
// 'ResponseContentLanguage' => 'en-US',
// 'ResponseContentDisposition' => 'attachment; filename=testing.txt',
// 'ResponseCacheControl' => 'No-cache',
// 'ResponseExpires' => gmdate(DATE_RFC2822, time() + 3600),
));
使用 minio 搭建私有对象存储云。aws-php-sdk 操作object的更多相关文章
- 使用CentOS8搭建私有NAS存储的一些建议
对于超过2TB的硬盘来说只能考虑GPT分区表,因此还是建议使用EFI来安装系统. 对于超过2TB的硬盘来说应该选择LVM,然后磁盘末尾预留出至少100G的空间用于将来方便维护安装个Windows系统之 ...
- 使用MinIO搭建对象存储服务
1.MinIO是什么? MinIO 是一款高性能.分布式的对象存储系统. 它是一款软件产品, 可以100%的运行在标准硬件.即X86等低成本机器也能够很好的运行MinIO. MinIO与传统的存储和其 ...
- 干货 | 基于Go SDK操作京东云对象存储OSS的入门指南
前言 本文介绍如何使用Go语言对京东云对象存储OSS进行基本的操作,帮助客户快速通过Go SDK接入京东云对象存储,提高应用开发的效率. 在实际操作之前,我们先看一下京东云OSS的API接口支持范围和 ...
- 阿里云对象存储OSS访问控制
阿里云对象存储OSS的Android SDK提供了STS鉴权模式和自签名模式来保障移动终端的安全性. OSS可以通过阿里云STS (Security Token Service) 进行临时授权访问.交 ...
- openstack-r版(rocky)搭建基于centos7.4 的openstack swift对象存储服务 四
openstack-r版(rocky)搭建基于centos7.4 的openstack swift对象存储服务 一 openstack-r版(rocky)搭建基于centos7.4 的openstac ...
- 听说你想把对象存储当 HDFS 用,我们这里有个方案...
传统的大数据集群往往采用本地中心化的计算和存储集群.比如在谷歌早期的[三驾马车]中,使用 GFS 进行海量网页数据存储,用 BigTable 作为数据库并为上层提供各种数据发现的能力,同时用 MapR ...
- ceph 对象存储跨机房容灾
场景分析 每个机房的Ceph都是独立的cluster,彼此之间没有任何关系. 多个机房都独立的提供对象存储功能,每个Ceph Radosgw都有自己独立的命名空间和存储空间. 这样带来两个问题: 针对 ...
- Docsify+腾讯云对象存储 COS,一键搭建云上静态博客
最近一直在想如何利用 COS 简化静态博客的搭建过程.搜了很多的静态博客搭建过程,发现大部分的静态博客都要通过编译才能生成静态页面.功夫不负有心人,终于让我找到了一个超简洁博客的搭建方法. 效果预览 ...
- 阿里云对象存储 OSS 应用服务器搭建代码
背景说明 最近做一个APP客户端图片直传阿里云OSS的服务,需要在后台开一个阿里云的OSSToken获取的接口. 阿里云官方文档地址:快速搭建移动应用直传服务. 略过移动端说明,直接看服务端的. 不是 ...
随机推荐
- BZOJ 一句话题解
菜鸡刷题记录 [题号:题解] 1008:简单排列组合 #include <bits/stdc++.h> using namespace std; #define ll long long ...
- AngularJS post传值后台获取不到
AngularJS post传值后台获取不到 一般的思路: 解决办法: 1.设置一下default head 2.参数转换一下data:$.param({orderNo: orderNo,sessi ...
- 【hihocoder】01背包
描述 且说上一周的故事里,小Hi和小Ho费劲心思终于拿到了茫茫多的奖券!而现在,终于到了小Ho领取奖励的时刻了! 小Ho现在手上有M张奖券,而奖品区有N件奖品,分别标号为1到N,其中第i件奖品需要ne ...
- 【学习ffmpeg】打开视频文件,帧分析,并bmp保存关键帧
http://www.tuicool.com/articles/jiUzua http://blog.csdn.net/code_future/article/details/8646717 主题 ...
- NFS 安装、管理
NFS简介 NFS允许一个系统在网络上与他人共享目录和文件.通过使用NFS,用户和程序可以像访问本地文件一样访问远程系统上的文件. 安装NFS 服务端安装 NFS安装包:nfs-utils-lib.i ...
- [转]Markdown 公式指导手册(包含LaTeX)
Cmd Markdown 公式指导手册 本文为转载文章,并且由于LaTeX的可能不能全部兼容,所以可能有部分公式无法在博客园显示,可以移步原网站. 本文固定链接: https://www.zybulu ...
- quartz(5)--作业管理和存储
作业一旦被调度,调度器需要记住并且跟踪作业和它们的执行次数.如果你的作业是30分钟后或每30秒调用,这不是很有用.事实上,作业执行需要非常准确和即时调用在被调度作业上的execute()方法.Quar ...
- bootstrap重置校验方法
$(function (){ $("select").change(function(){ $('#DepartForm').bootstrapValidator('resetFo ...
- Oracle常见的几种登录方式
1.运行SQLPLUS工具 C:\Users\csb>sqlplus(回车) (输入账户)system(回车) (输入密码) (回车) 2.直接进入SQLPLUS命令提示符,无用户的登陆 C:\ ...
- oracle 结构化语言查询 DML DDL DCL
--结构化查询语言 (Structured Query Language),具有定义. --查询.更新和控制等多种功能,是关系数据库的标准语言. --SQL分类: -- 数据操纵语言DML Data ...