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();
總結
以上是生活随笔為你收集整理的aws s3 php,Amazon S3 预签名 POSTs 与 AWS SDK for PHP 版本 3 - 适用于 PHP 的 AWS 开发工具包...的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: php验证数字100倍数,js如何实现一
- 下一篇: 动态规划算法php,php算法学习之动态