使用时的Amazon S3无效日期在url_for中过期 [英] Amazon S3 invalid date when using expires in url_for

查看:417
本文介绍了使用时的Amazon S3无效日期在url_for中过期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Amazon s3存储桶中创建一个文档.然后,我尝试为该存储桶创建一个已签名的URL,该URL从现在起几年后失效,如下所示:

I create a document in an Amazon s3 bucket. I then try to create a signed url to that bucket that expires a few years from now as follows:

s3 = AWS::S3.new(:access_key_id => S3Config.access_key_id, :secret_access_key => S3Config.secret_access_key)
    bucket = s3.buckets[S3Config.bucket]
    bucket.objects[s3_key].url_for(:read, :expires => Time.at(Time.utc(2019,12,30)).to_i)

但是当我导航到签名的URL时,会收到以下错误消息:

But when I navigate to the signed url I get the following error message:

Invalid date (should be seconds since epoch)

但是根据 Time.at的ruby文档, 和我对时代的理解,这应该起作用...我在做什么错了?

But according to the ruby docs for Time.at, and my understanding of epoch time, this should work...what am I doing wrong?

推荐答案

文档和示例指出,异常文本可能来自更深层次的内容,并最终产生误导.

The exception text may be coming from something deeper and ends up misleading, the docs and examples state:

:expires (对象)-设置URL的到期时间;在此之后,如果使用了URL,S3将返回错误. 这可以是整数(以指定当前时间之后的秒数),也可以是字符串(使用Time#parse解析为日期),时间或DateTime对象.此选项默认为当前时间之后的一小时.

:expires (Object) — Sets the expiration time of the URL; after this time S3 will return an error if the URL is used. This can be an integer (to specify the number of seconds after the current time), a string (which is parsed as a date using Time#parse), a Time, or a DateTime object. This option defaults to one hour after the current time.

基于此,我认为您正在做太多工作,请尝试以下操作:

Based on that, I think you're doing too much work, try this:

expires: Time.utc(2019, 12, 3)

这篇关于使用时的Amazon S3无效日期在url_for中过期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆