使用 Fog 创建文件时保留(或明确设置)Last-Modified ("mtime")

Preserving (or explicitly setting) Last-Modified ("mtime") when creating files with Fog

我正在尝试将文件复制到云中(同时复制到 SoftLayer 和 AWS)并且我需要保留 "Last-Modified" header,所以当我从云中取回它时我会看到我提供的 last_modified 时间。 我不知道该怎么做。我尝试过这些方法:

dir = s3.directories.get("mybucket")
last_modified = Time.at(1437600000) # some time in July 23

dir.files.create(key: "file1.txt", body: "content string", last_modified: last_modified.httpdate)

dir.files.create(key: "file2.txt", body: "content string", last_modified: last_modified)

dir.files.create(key: "file3.txt", body: "content string", 'Last-Modified' => last_modified)

dir.files.create(key: "file4.txt", body: "content string", 'Last-Modified' => last_modified.httpdate)

path = "/tmp/to_upload.txt"
File.open(path, "w+") { |file|
  file.write("content string")
}
FileUtils.touch(path, mtime: last_modified)
dir.files.create(key: "file5.txt", body: open(path))

但是所有文件都是使用当前时间戳而不是我提供的旧日期创建的:

$ aws s3 ls s3://mybucket/file
2015-07-30 15:21:25         14 file1.txt
2015-07-30 15:21:26         14 file2.txt
2015-07-30 15:21:27         14 file3.txt
2015-07-30 15:21:28         14 file4.txt
2015-07-30 15:21:28         14 file5.txt

不幸的是,AWS S3 不允许用户修改最后修改的值。它将始终设置为您在服务器端修改的时间。您可以在此处详细了解哪些元数据值可以修改(或不修改):http://docs.aws.amazon.com/AmazonS3/latest/dev/UsingMetadata.html#object-metadata