aws s3 php,Amazon S3 预签名 POSTs 与 AWS SDK for PHP 版本 3 - 适用于 PHP 的 AWS 开发工具包...

AWS 文档中描述的 AWS 服务或功能可能因区域而异。要查看适用于中国区域的差异,请参阅中国的 AWS 服务入门。

本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。

Amazon S3 预签名 POSTs 与 AWS SDK for PHP 版本 3

与预签名 URLs 极其相似,预签名 POSTs 使您无需向用户提供 AWS 凭证便可向其授予写入访问权限。可在 AwsS3PostObjectV4 实例的帮助下创建预签名 POST 表单。

以下示例演示如何:

版本 3 的所有示例代码在 AWS SDK for PHP 上的此处提供。GitHub

Credentials

创建PostObjectV4

要创建 PostObjectV4 的实例,必须提供以下内容:

Aws\S3\S3Client 的实例

存储桶

表单输入字段的关联数组

策略条件数组(请参见 Amazon S3 Developer Guide 中的策略构造)

策略的过期时间字符串(可选,默认为 1 小时)。

导入

require 'vendor/autoload.php';

use Aws\S3\S3Client;

use Aws\Exception\AwsException;

示例代码

$client = new S3Client([

'profile' => 'default',

'version' => 'latest',

'region' => 'us-west-2',

]);

$bucket = 'mybucket';

// Set some defaults for form input fields

$formInputs = ['acl' => 'public-read'];

// Construct an array of conditions for policy

$options = [

['acl' => 'public-read'],

['bucket' => $bucket],

['starts-with', '$key', 'user/eric/'],

];

// Optional: configure expiration time string

$expires = '+2 hours';

$postObject = new \Aws\S3\PostObjectV4(

$client,

$bucket,

$formInputs,

$options,

$expires

);

// Get attributes to set on an HTML form, e.g., action, method, enctype

$formAttributes = $postObject->getFormAttributes();

// Get form input fields. This will include anything set as a form input in

// the constructor, the provided JSON policy, your AWS access key ID, and an

// auth signature.

$formInputs = $postObject->getFormInputs();

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值