Incorrect S3 url
Reported by Mark Dodwell | June 21st, 2008 @ 11:56 AM
S3 urls should have the bucket name as part of the domain. For a bucket 'foo' and a file 'bar.zip' the URL should be:
http://foo.s3.amazonaws.com/bar.zip
But in Paperclip it provides:
http://s3.amazonaws.com/foo/bar.zip
I believe that you need to change line 103 in storage.rb from:
"https://s3.amazonaws.com/#{attachment.bucket_name}/#{attachment.path(style).gsub(%r{^/}, "")}"
to
"https://#{attachment.bucket_name}.s3.amazonaws.com/#{attachment.path(style).gsub(%r{^/}, "")}"
Comments and changes to this ticket
-
-
Jon Yurek June 21st, 2008 @ 10:36 PM
S3 allows for bucket names that aren't allowed in subdomains, so this is a more general solution. Is this actually a problem? Is there some reason that subdomains are preferable?
-
Mark Dodwell June 22nd, 2008 @ 05:00 AM
Sure, after some more investigation I think this only affected me
because of the way my S3 bucket was created.
I had an S3 bucket where I could only access it using the sub-domain
format not the path format. According to the Amazon S3 docs (http://
docs.amazonwebservices.com/AmazonS3/2006-03-01/
BucketConfiguration.html), if you create a bucket using
'CreateBucketConfiguration' then you must only use the sub-domain
format. (Incidentally I created it using Transmit, and never
specified explicitly the 'CreateBucketConfiguration'!)
Given this, perhaps there should be an additional option to allow you
to specify the url format (either domain, or path based)? What do you
think?
-
Jon Yurek June 25th, 2008 @ 09:46 AM
- → State changed from new to open
- → Tag changed from to bug s3 url
I suppose that would be fine. If you can supply a patch I'd be happy to apply it.
-
Jon Yurek July 25th, 2008 @ 12:34 PM
- → State changed from open to hold
-
Mark Dodwell August 7th, 2008 @ 01:20 PM
- → Tag changed from bug s3 url to feature options patch s3 url
Sorry for the delay -- I've attached a patch to add a new option for S3 storage.
It simply adds a new option called :url_format which can be one of 2 symbols :subdomain or :path (default).
Patch (with updated rdoc) attached.
-
Jon Yurek August 8th, 2008 @ 03:55 PM
- → State changed from hold to open
This looks good, but can you add some tests for it? Thanks.
-
Gregory Man August 8th, 2008 @ 06:52 PM
Thank u. Can u add, options to switch between https and http?
-
Gregory Man August 14th, 2008 @ 04:55 AM
Hi this is little bit improved version of Mark's patch. Added documentation, http/https switch, and tests.
Thanks.
-

Yaroslav Markin August 21st, 2008 @ 08:38 AM
Got a small proposal.
How about defaulting
@use_https = @options[:use_https] || :true
To :false if we use 'public-read' permission (default) and :true otherwise?
-

-
Jon Yurek August 21st, 2008 @ 11:21 AM
- → State changed from open to resolved
I've committed a fix for this to master. Instead of having another option for the url construction method, I've changed it so that the :url option can take :s3_domain_url or :s3_path_url as options. It defaults to :s3_path_url.
Also, there is an :s3_protocol option that can be either 'http' or 'https'. If the permissions are set to 'public-read' (and they are, be default), then it will use 'http' by default and otherwise 'https' by default. So, under normal circumstances, you won't have to change either.
Please Login or create a free account to add a new comment.
You can update this ticket by sending an email to from your email client. (help)
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »
