使用时的 Amazon S3 无效日期在 url_for 后到期

Amazon S3 invalid date when using expires in url_for

我在 Amazon s3 存储桶中创建了一个文档。然后,我尝试为该桶创建一个已签名的 url,该桶将在几年后到期,如下所示:

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 时,我收到以下错误消息:

Invalid date (should be seconds since epoch)

但是根据 Time.at 的 ruby 文档以及我对纪元时间的理解,这应该可行...我做错了什么?

异常文本可能来自更深层次的东西,最终会产生误导,文档和示例声明:

: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.

基于此,我认为你做的工作太多了,试试这个:

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