内容类型限制在亚马逊s3政策中不起作用: 使用此策略,我可以上传任何文件类型,我必须仅限制pdf文件
以下是我的代码:
$bucket = 'test'; // the name you've chosen for the bucket
$key = 'upload/${filename}';
$success_action_redirect = 'localhost/test.html';
$content_type = 'application/pdf';
$acl = 'private';
$policy = '
{ "expiration": "2016-08-23T12:00:00.000Z",
"conditions": [
{"bucket": "'.$bucket.'"},
["starts-with", "$key", ""],
{"acl": "'.$acl.'"},
{"success_action_redirect": "'.$success_action_redirect.'"},
["starts-with", "$Content-Type", "'.$content_type.'"],
{"x-amz-meta-uuid": "14365123651274"},
["starts-with", "$x-amz-meta-tag", ""],
["content-length-range", 0, 10485760]
]
}';
<form action="bucketUrl" method="post" enctype="multipart/form-data"
id="s3-post">
<input type="hidden" name="key" value="<?php echo $key; ?>">
<input type="hidden" name="acl" value="<?php echo $acl; ?>">
<input type="hidden" name="success_action_redirect" value="<?php echo $success_action_redirect; ?>">
<input type="hidden" name="Content-Type" value="<?php echo $content_type; ?>">
<input type="hidden" name="x-amz-meta-uuid" value="14365123651274">
<input type="hidden" name="x-amz-meta-tag" value="">
<input type="hidden" name="AWSAccessKeyId" value="<?php echo $aws_access_key; ?>">
<input type="hidden" name="Policy" value="<?php echo base64_encode($policy); ?>">
<input type="hidden" name="Signature" value="<?php echo base64_encode(hash_hmac('sha1', base64_encode($policy), $aws_secret_key, true)); ?>">
<input type="file" name="file" class="input_file">
<input type="submit" name="submit" class="s3_upload" value="Upload to Amazon S3">