【问题标题】:Fine Uploader S3 - Return Uploaded URL on Complete callbackFine Uploader S3 - 在完成回调时返回上传的 URL
【发布时间】: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...',这让我相信您为此使用了错误的密钥。

标签: amazon-s3 fine-uploader


【解决方案1】:

让您的uploadSuccess.endpoint 返回一个pre-signed URL,然后在onComplete 处理程序中处理它。请注意,预签名 URL 只能在服务器端生成。见this PHP server for details

【讨论】:

  • 谢谢马克,但我仍然无法正常工作。如果您有任何想法,我已经用更多信息更新了我的问题?
  • @odd_duck 查看标记引用的 PHP 服务器。如果您正确实施,这将按预期工作。
  • 我刚刚尝试将我的 end.php 更改为链接到 https://github.com/Widen/fine-uploader-server/blob/master/php/s3/s3demo-thumbnails-cors.php#L241-L248 的那个,而不是原来的 https://github.com/Widen/fine-uploader-server/blob/master/php/s3/s3demo-cors.php,但我仍然没有得到任何回应。 serverPublicKeyserverPrivateKey 是正确的还是应该留空?一切都按照我上面的说明进行设置
  • 看起来您的服务器根本没有返回包含 tempLink 属性的响应。这在您发布的屏幕截图中很清楚。
猜你喜欢
  • 2014-07-10
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-07-22
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多