Gavriel
Gavriel

Reputation: 19237

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

I am trying to copy a file into the cloud (both to SoftLayer and to AWS) and I need to preserve the "Last-Modified" header, so when I retrieve it back from the clouds I would see the last_modified time I provided. I can't figure out how to do it. I tried it in these ways:

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))

But all of the files were created with the current timestamp instead of the older date I provided:

$ 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

Upvotes: 0

Views: 359

Answers (1)

geemus
geemus

Reputation: 2542

Unfortunately, AWS S3 does not allow the user to modify the last-modified value. It will always be set as the time at which you modify on the server side. You can read a bit more about which metadata values can be modified (or not) here: http://docs.aws.amazon.com/AmazonS3/latest/dev/UsingMetadata.html#object-metadata

Upvotes: 1

Related Questions