我在访问Amazon S3中的存储桶时遇到问题。我按照官方博客(Fineuploader S3从浏览器直接上传到Amazon S3)逐步按照Fineuploader中的说明进行操作,我检查了类似的问题,但没有提到这个特定情况。
我的意图是复制用于S3的fineuploader.com演示,唯一的区别是我没有使用高级功能(分块,拖放,重试等),换句话说,制作一个& #34;简单上传"。
对不起,如果我非常多余或非常明确,我只想说明我已经完成的程序。
我在http://fineuploader.com/demos.html#amazon-demo的客户端复制了代码并更改了一些行:
<!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>
我在服务器端的代码仅来自https://github.com/FineUploader/server-examples/blob/master/php/s3/s3demo-thumbnails-cors.php评论并更改了以下注释。
评论说明:
// require 'aws-autoloader.php';
// use Aws\S3\S3Client;
// $serverPublicKey = $_SERVER['PARAM1'];
// $serverPrivateKey = $_SERVER['PARAM2'];
// $expectedMaxSize = 15000000;
更改了行:
// Secret key - User create in IAM
$clientPrivateKey = $_SERVER['BIsYDPrOfWyWeUXueJaiaAem7he3R5THxx000Xxx'];
$expectedBucketName = "bucketname";
所有内容都显示正常,但是当我上传图片时,我的Chrome控制台出错:
POST http://bucketname.s3.amazonaws.com/ 403 (Forbidden)
访问密钥和密钥包含为说明目的而放置的字符X和0。钥匙不是真的。
感谢您的帮助。
答案 0 :(得分:2)
$clientPrivateKey = $_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';
我还建议您更换钥匙,因为您现在已将其发布在公共场所,并且有人必然会对您的桶进行讨厌的事情!