gpt4 book ai didi

jquery - S3 "Invalid according to Policy: Policy expired"

转载 作者:行者123 更新时间:2023-12-01 01:07:40 25 4
gpt4 key购买 nike

我最近在尝试本地上传图像时开始遇到此错误。不过,我以前不习惯收到错误。 S3 方面或代码方面没有任何变化。不过,上传在生产中仍然有效。我已经尝试了所有常见的方法,重新启动服务器,重新启动计算机,更改为不同的浏览器,清除缓存/cookie,更改策略中的过期时间,检查我的 ENV 变量是否存在且是否正确......

这是我使用 jQuery Fileupload 的 CoffeeScript

$("input.fileupload").fileupload
url: '<%= s3_bucket_url %>'
type: 'POST'
autoUpload: true
dataType: 'xml'
paramName: 'file'
acceptFileTypes: /(\.|\/)(jpg|png)$/i
formData:
key: '<%= "tmp-uploads/#{SecureRandom.uuid}/${filename}" %>'
AWSAccessKeyId: '<%= Settings.fog.aws_access_key_id %>'
acl: 'public-read'
policy: '<%= s3_policy %>'
signature: '<%= s3_signature %>'
success_action_status: '201'
success: (data)->
# success stuff
fail: (e, data)->
# fail stuff

这是我的 S3 助手

module S3Helper

def s3_bucket_url
"https://#{Settings.fog.directory}.s3.amazonaws.com"
end

def s3_signature
Base64.encode64(
OpenSSL::HMAC.digest(
OpenSSL::Digest::Digest.new('sha1'),
Settings.fog.aws_secret_access_key,
s3_policy
)
).gsub(/\n/, '')
end

def s3_policy
Base64.encode64(
{
expiration: 24.hours.from_now.utc.strftime('%Y-%m-%dT%H:%M:%SZ'),
conditions: [
{ bucket: Settings.fog.directory },
{ acl: 'public-read' },
['starts-with', '$key', 'tmp-uploads/'],
{ success_action_status: '201' }
]
}.to_json
).gsub(/\n|\r/, '')
end
end

我的想法已经用完了。我需要添加“内容类型”吗?任何方向将不胜感激。

最佳答案

如果正如你所说,并且你的代码没有任何改变,我的猜测是:

Why do some of my requests randomly fail with a 403 Forbidden?

Check the system clock and time zone settings on the offending machine. Amazon S3 requires all machines making requests be within 15 minutes of an Amazon S3 webserver's clock. Setting up your machines to sync their times with an NTP server in addition to making sure they are patched for the recent Day Light Savings changes should resolve this issue.

This is a common error when a developer decides to deploy their application to another machine.

The response from Amazon S3 will contain the following:

  • HTTP Status Code: 403 Forbidden
  • Error Code: RequestTimeToo-Skewed
  • Description: The difference between the request time and the server's time is too large.

您必须正确设置时区,不能简单地将时钟向上或向下调整一个小时。

关于jquery - S3 "Invalid according to Policy: Policy expired",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19506275/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com