Skip to content

Conversation

acoustep
Copy link
Contributor

Hi,

Thanks for creating this great package.

I'm in a situation where I'd like to be able to access object meta data without fetching the files.

I thought it would be useful to add this as a method head_object as this is the API that AWS uses. I've also added a new response type for it.

I think it would also be nice to use Crystal's Time class for last_modified, but I had some trouble parsing the date format so I've left it as-is.

@taylorfinnell
Copy link
Owner

Thank you!

I think you should be able to parse the last modified like this. https://github.com/taylorfinnell/awscr-s3/blob/master/src/awscr-s3/responses/list_objects_v2.cr#L26

Also, looks like ameba is not working with Crystal 0.29.0 and making CI fail. I can try to update that later today or you can if you want

@acoustep
Copy link
Contributor Author

Ah thanks @taylorfinnell I had not seen that :).

I've updated the code to parse the time.

I'm not sure on the Ameba stuff, I'm currently using 0.28.0 on my project and haven't upgraded yet I'm afraid.

@acoustep
Copy link
Contributor Author

acoustep commented Jun 20, 2019

I've just been looking a bit more into the timezone formatting. I'm using a aws s3 compatible api (min.io) and Last-Modified returns a format like this Wed, 19 Jun 2019 11:55:33 GMT.

I'm assuming AWS S3 uses the same format, and with the format "%FT%T" I'm unable to parse it correctly.

I was, however, able to get it working with this

    DATE_FORMAT = "%a, %d %b %Y %l:%M:%S"
    # ...
      last_modified_words = response.headers["Last-Modified"].split(" ")
      timezone = Time::Location.local = Time::Location.load(last_modified_words.pop)
      last_modified = last_modified_words.join(" ")
      Time.parse(last_modified, DATE_FORMAT, timezone)

I just wanted to check this is correct for all S3 compatible APIs before I updated the pull request. Are you able to confirm if the current code works?

@taylorfinnell
Copy link
Owner

taylorfinnell commented Jun 20, 2019

I think you are correct

https://docs.aws.amazon.com/AmazonS3/latest/API/RESTObjectHEAD.html
vs
https://docs.aws.amazon.com/AmazonS3/latest/API/v2-RESTBucketGET.html

Check out the sample response section
I assumed they would be the same, my bad

@acoustep
Copy link
Contributor Author

No worries, I've updated the code to work with the different format.

@taylorfinnell
Copy link
Owner

If you can run a crystal tool format should be good to merge

@acoustep
Copy link
Contributor Author

No problem, I’m away from my machine for the next few days but I’ll get it done later this week.

@acoustep
Copy link
Contributor Author

I've run the formatter 👍

@taylorfinnell
Copy link
Owner

Thanks!

@taylorfinnell taylorfinnell merged commit 7cdaac0 into taylorfinnell:master Jun 28, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants