Amazon S3 Query String Authentication and Ruby on Rails
Amazons S3 added this summer a new way to allow people to access your files stored on S3. This method is called Query String Authentication and by generating an url for a private file you can offer access to that file for a limited amount of time. First upload a file to Amazon S3 and use the acl ‘private’ to store the file. To generate the url for to such a link I’ve made a helper for Ruby on Rails:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
|
This method generates an url which is valid for 10 days. I’m now 100% sure of the gsub method to convert spaces in a resource filename to a plus sign, maybe there are more characters you should be aware of. Anyway this method is based on the SWF Upload post.
Update: Thanks to Simon, I’ve updated the example where it would produce an invalid signature. The plus sign in the url needs to be url encoded.
Update 2: Rob provided a Ruby 1.9 only version.