Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Allow presence of s3 url encoded keys #736

Closed
wants to merge 5 commits into from

1 participant

@freegenie

Hi there,
here is my solution to this issue:

#735

I think it's a simple yet clean way to allow people to use paperclip to deal with their existing S3 file base. It does not break existing functionality neither it changes the default behavior. It's just an under the hood additional feature. I made my app run with it and it resolves my problem.

@freegenie

Sorry forget about this. This started from a wrong assumption, the problem no longer exists to me.

@freegenie freegenie closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
Showing with 33 additions and 2 deletions.
  1. +1 −1  lib/paperclip/storage/s3.rb
  2. +32 −1 test/storage/s3_test.rb
View
2  lib/paperclip/storage/s3.rb
@@ -194,7 +194,7 @@ def s3_bucket
end
def s3_object style_name = default_style
- s3_bucket.objects[path(style_name).sub(%r{^/},'')]
+ s3_bucket.objects[URI.escape(path(style_name).sub(%r{^/},''))]
end
def using_http_proxy?
View
33 test/storage/s3_test.rb
@@ -208,7 +208,7 @@ def teardown
end
end
- context "An attachment that uses S3 for storage and has spaces in file name" do
+ context "A new attachment that uses S3 for storage and has spaces in file name" do
setup do
rebuild_model :styles => { :large => ['500x500#', :jpg] },
:storage => :s3,
@@ -231,6 +231,37 @@ def teardown
end
end
+ context "A saved attachment that uses S3 for storage and has spaces in file name" do
+ setup do
+ rebuild_model :styles => { :large => ['500x500#', :jpg] },
+ :storage => :s3,
+ :bucket => "bucket",
+ :s3_credentials => {
+ 'access_key_id' => "12345",
+ 'secret_access_key' => "54321"
+ }
+
+ @dummy = Dummy.new
+ @dummy.avatar = File.new(fixture_file('spaced file.png'), 'rb')
+ @dummy.save!
+ @dummy.update_attributes(:avatar_file_name => 'spaced file.png')
+ @dummy = Dummy.find(@dummy.id)
+ end
+
+ should "return an untouched version for path" do
+ assert_match /.+\/spaced file\.png/, @dummy.avatar.path
+ end
+
+ should "return an URI escaped version for url" do
+ assert_match /.+\/spaced%20file\.png/, @dummy.avatar.url
+ end
+
+ should 'have the s3_object key escaped' do
+ assert_match /.+\/spaced%20file\.png/, @dummy.avatar.s3_object.key
+ end
+
+ end
+
context "An attachment that uses S3 for storage and has a question mark in file name" do
setup do
rebuild_model :styles => { :large => ['500x500#', :jpg] },
Something went wrong with that request. Please try again.