【发布时间】:2014-05-17 00:46:40
【问题描述】:
如何使用 Fine-uploader 在我的 amazon s3 存储桶上获取已上传图片的完整图片网址?
我的 javascript 代码是:
jQuery(document).ready(function () {
jQuery("#fine-uploader").fineUploaderS3({
debug: true,
request: {
endpoint: 'bucket.s3.amazonaws.com',
accessKey: 'xxxxxxxx'
},
signature: {
endpoint: 'end.php '
},
uploadSuccess: {
endpoint: 'success.php '
},
iframeSupport: {
localBlankPagePath: 'success.html '
},
retry: {
enableAuto: true
},
validation: {
allowedExtensions: ['
jpeg ', '
jpg ', '
png '],
sizeLimit: 1048576
}
}).on('
complete ', function (event, id, name, response) {
console.log(response.tempLink);
});
});
更新
在 s3 演示之后,我使用 response.tempLink 并尝试将其记录到控制台,然后我将在稍后使用它。上传总是可以正常工作,但我的控制台每次都返回一个未定义的响应。
从找到这个问答:having trouble displaying an image uploaded to Amazon s3 by fine-uploader
似乎我的 IAM 用户/策略设置和 $serverPublicKey 和 $serverPrivateKey 可能是原因?我的设置是:
我的 end.php 文件的此文件的精确副本: https://github.com/Widen/fine-uploader-server/blob/master/php/s3/s3demo-cors.php
进行以下更改:
// changed to match the secret access key for the FIRST IAM user as discussed in the docs
$clientPrivateKey = 'user_secret_key...';
// bucket name
$expectedBucketName = "my.bucket.name";
// changed to match the access and secret of the SECOND IAM 'server' user
$serverPublicKey = 'server_user_access_key...';
$serverPrivateKey = 'server user secret key...';
// updated to my website
function handlePreflightedRequest() {
header('Access-Control-Allow-Origin: http://www.mywebsite.com');
}
在我的 Amazon IAM 控制台中,我将 mt SECOND IAM 'server' 用户设置为:
组: grp-服务器
组策略:(GetObject 是正确的操作吗?)
{
"Version":"2012-10-17",
"Statement":[{
"Effect":"Allow",
"Action":"s3:GetObject",
"Resource":"arn:aws:s3:::my.bucket.name/*"
}]
}
或者我已经尝试了以下提供完全管理员访问权限的方法来检查
{
"Version":"2012-10-17",
"Statement":[{
"Effect":"Allow",
"Resource":"*"
}]
}
用户: 用户服务器 添加到 grp-server(继承组策略)
user-server access key becomes $serverPublicKey in end.php
user-server secret key becomes $serverPrivateKey in end.php
我错过了什么吗?
【问题讨论】:
-
这在fineuploader.com/demos#amazon-demo 的演示中有所介绍。您的服务器只需要在其 JSON 响应中返回 URL。
-
感谢@RayNicholus,但我仍然无法让它工作。我的回复链接始终未定义。我已经编辑并更新了我的原始问题,并提供了更多详细信息...
-
如果响应对象不包含 tempLink,则您的服务器不会返回包含 tempLink 属性的 JSON 响应。您需要仔细查看您的服务器代码。根据您在此处粘贴的内容,您确实没有返回带有 responseLink 属性的 JSON 响应。
-
当我使用
console.dir(response);时,我得到屏幕截图中显示的控制台响应:oi62.tinypic.com/2nibp6s.jpg -
GetObject是正确的。$clientPrivateKey应该是客户端的密钥。现在看起来您将其设置为'user_access_key...',这让我相信您为此使用了错误的密钥。