Php 拒绝访问S3中的存储桶-错误403禁止(精细上载程序)
我在AmazonS3中访问bucket时遇到问题。我按照官方博客Fineuploader(Fineuploader S3从您的浏览器直接上传到Amazon S3)中的说明一步一步地进行操作,我检查了类似的问题,但没有一个问题涉及到这个具体案例 我的目的是复制fineuploader.com的S3演示,唯一的区别是我没有使用高级功能(分块、拖放、重试等),换言之,是“简单上传” 请原谅,如果我是非常多余或非常明确的,我只想说明我所做的程序 我复制了客户端的代码,并更改了一些行:Php 拒绝访问S3中的存储桶-错误403禁止(精细上载程序),php,amazon-s3,fine-uploader,Php,Amazon S3,Fine Uploader,我在AmazonS3中访问bucket时遇到问题。我按照官方博客Fineuploader(Fineuploader S3从您的浏览器直接上传到Amazon S3)中的说明一步一步地进行操作,我检查了类似的问题,但没有一个问题涉及到这个具体案例 我的目的是复制fineuploader.com的S3演示,唯一的区别是我没有使用高级功能(分块、拖放、重试等),换言之,是“简单上传” 请原谅,如果我是非常多余或非常明确的,我只想说明我所做的程序 我复制了客户端的代码,并更改了一些行: <!DOCT
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="description" content="">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="shortcut icon" href="favicon.ico" >
<title></title>
<!--[if lt IE 9]>
<script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
</head>
<body>
<!-- jQuery ====================================================================== -->
<script src="http://code.jquery.com/jquery-latest.js"></script>
<!-- Fine Uploader JS ====================================================================== -->
<script src="../../custom.fineuploader-5.0.8.js"></script>
<script>
$(document).ready(function () {
$('#fineuploader-s3').fineUploaderS3({
debug: true,
request: {
// REQUIRED: We are using a custom domain
// for our S3 bucket, in this case. You can
// use any valid URL that points to your bucket.
endpoint: "bucketname.s3.amazonaws.com",
// REQUIRED: The AWS public key for the client-side user
// we provisioned.
// Access key - User create in IAM
accessKey: "AKIAJUGFU2PN7PXXXXXX"
},
template: "simple-previews-template",
// REQUIRED: Path to our local server where requests
// can be signed.
signature: {
endpoint: "/fineuploader/html/templates/s3demo.php"
},
// OPTIONAL: An endopint for Fine Uploader to POST to
// after the file has been successfully uploaded.
// Server-side, we can declare this upload a failure
// if something is wrong with the file.
uploadSuccess: {
endpoint: "/fineuploader/html/templates/s3demo.php?success"
},
// USUALLY REQUIRED: Blank file on the same domain
// as this page, for IE9 and older support.
// iframeSupport: {
// localBlankPagePath: "/server/success.html"
// },
// optional feature
// chunking: {
// enabled: true
// },
// optional feature
// resume: {
// enabled: true
// },
// optional feature
// deleteFile: {
// enabled: true,
// method: "POST",
// endpoint: "/s3demo.php"
// },
// optional feature
// validation: {
// itemLimit: 5,
// sizeLimit: 15000000
// },
// thumbnails: {
// placeholders: {
// notAvailablePath: "images/not_available-generic.png",
// waitingPath: "images/waiting-generic.png"
// }
// }
})
// Enable the "view" link in the UI that allows the file to be downloaded/viewed
.on('complete', function(event, id, name, response) {
var $fileEl = $(this).fineUploaderS3("getItemByFileId", id),
$viewBtn = $fileEl.find(".view-btn");
if (response.success) {
$viewBtn.show();
$viewBtn.attr("href", response.tempLink);
}
});
});
</script>
<!-- Fine Uploader CSS ====================================================================== -->
<link href="../../custom.fineuploader-5.0.8.css" rel="stylesheet">
<!-- Fine Uploader DOM Element ====================================================================== -->
<div id="fineuploader-s3"></div>
<!-- Fine Uploader template ====================================================================== -->
<script type="text/template" id="simple-previews-template">
<div class="qq-uploader-selector qq-uploader">
<div class="qq-upload-drop-area-selector qq-upload-drop-area" qq-hide-dropzone>
<span>Drop files here to upload</span>
</div>
<div class="qq-upload-button-selector qq-upload-button">
<div>Upload a file</div>
</div>
<span class="qq-drop-processing-selector qq-drop-processing">
<span>Processing dropped files...</span>
<span class="qq-drop-processing-spinner-selector qq-drop-processing-spinner"></span>
</span>
<ul class="qq-upload-list-selector qq-upload-list">
<li>
<div class="qq-progress-bar-container-selector">
<div class="qq-progress-bar-selector qq-progress-bar"></div>
</div>
<span class="qq-upload-spinner-selector qq-upload-spinner"></span>
<img class="qq-thumbnail-selector" qq-max-size="100" qq-server-scale>
<span class="qq-edit-filename-icon-selector qq-edit-filename-icon"></span>
<span class="qq-upload-file-selector qq-upload-file"></span>
<input class="qq-edit-filename-selector qq-edit-filename" tabindex="0" type="text">
<span class="qq-upload-size-selector qq-upload-size"></span>
<a class="qq-upload-cancel-selector btn-small btn-warning" href="#">Cancel</a>
<a class="qq-upload-retry-selector btn-small btn-info" href="#">Retry</a>
<a class="qq-upload-delete-selector btn-small btn-warning" href="#">Delete</a>
<a class="qq-upload-pause-selector btn-small btn-info" href="#">Pause</a>
<a class="qq-upload-continue-selector btn-small btn-info" href="#">Continue</a>
<span class="qq-upload-status-text-selector qq-upload-status-text"></span>
<a class="view-btn btn-small btn-info hide" target="_blank">View</a>
</li>
</ul>
</div>
</script>
</body>
</html>
换行:
// Secret key - User create in IAM
$clientPrivateKey = $_SERVER['BIsYDPrOfWyWeUXueJaiaAem7he3R5THxx000Xxx'];
$expectedBucketName = "bucketname";
看起来一切正常,但当我上传图像时,我的Chrome控制台出现错误:
POST http://bucketname.s3.amazonaws.com/ 403 (Forbidden)
访问密钥和密钥包含字符X和0,它们是为了说明目的而放置的。钥匙不是真的
非常感谢您的帮助。
$clientPrivateKey=$\u SERVER['xxx']代码>
我认为这是错误的。原始文件中写道:
// These assume you have the associated AWS keys stored in
// the associated system environment variables
$clientPrivateKey = $_SERVER['AWS_SECRET_KEY'];
因此,要么在您的环境中设置一个名为AWS_SECRET_KEY的变量并将该行还原为原来的状态,要么只使用
$clientPrivateKey='xxx'代码>
我还建议你换一下钥匙,因为你现在已经把它贴在公共场所了,肯定会有人对你的桶做坏事 访问密钥和密钥包含字符X和0,它们是为了说明目的而放置的。密钥不是真的我的意思是,从$_服务器[“…”]更改为“…”,非常感谢,它真的很有帮助
// These assume you have the associated AWS keys stored in
// the associated system environment variables
$clientPrivateKey = $_SERVER['AWS_SECRET_KEY'];