I am using Paperclip to store images using S3. It’s my understanding that Paperclip will append a string (timestamp) to the end of the image for caching purposes. Do you know what method they use to create the string? I need to rebuild it using .js, here’s why:
I am getting content using jQuery’s $.getJSON, parsing the response data, building an array and adding it to the DOM. Everything works great with that, but I need to add the string on to the end of the file name.
Here’s an example:
<img src="http://s3.amazonaws.com/some_bucket/some_image.jpg?1293603533" />
Although the URL is an example, the string appended to the file name is actual. Here is the other data on this image.
image_file_size: 159713
image_height: 415
image_width: 900
image_updated_at: 2010-12-29 06:18:53
I thought it’d be as easy as stripping all “:” and “-” from the image_updated_at attribute but it doesn’t look that easy. Is it completely random? Anyone have any idea on this? I’d appreciate a hand!
I looked into Rails source and this
asset_idis computed in this line:So it is just converting
Timeobject to integer. And ruby docs says that it is just number of seconds since epoch.Here is example how to convert date in js to the same format as in ruby
to_i. I’ve checked it and it gives the same value.