qoobaa / s3

Library for accessing S3 objects and buckets, supports EU and US buckets
MIT License
258 stars 112 forks source link

Copy fails if the file name has two simultaneous spaces #86

Open k6s3 opened 10 years ago

k6s3 commented 10 years ago

I've implemented a direct to s3 file upload mechanism, where the file first gets uploaded to the bucket root and then gets copied over to its final resting place using a copy command..

The copy fails if the file name has two spaces, as illustrated below -

1.9.3p484 :052 > s3_object_1 = artifact.attachment.bucket.objects.find("a  b.pdf")
 => #<S3::Object:/my-bucket/a  b.pdf> 
1.9.3p484 :053 > s3_object_1.copy(:key => "copy_of_file_1.pdf", :acl => :private)
S3::Error::SignatureDoesNotMatch: The request signature we calculated does not match the signature you provided. Check your key and signing method.
  from /home/user_name/.rvm/gems/ruby-1.9.3-p484/gems/s3-0.3.11/lib/s3/connection.rb:217:in `handle_response'
  from /home/user_name/.rvm/gems/ruby-1.9.3-p484/gems/s3-0.3.11/lib/s3/connection.rb:204:in `send_request'
  from /home/user_name/.rvm/gems/ruby-1.9.3-p484/gems/s3-0.3.11/lib/s3/connection.rb:89:in `request'
  from /home/user_name/.rvm/gems/ruby-1.9.3-p484/gems/s3-0.3.11/lib/s3/service.rb:74:in `service_request'
  from /home/user_name/.rvm/gems/ruby-1.9.3-p484/gems/s3-0.3.11/lib/s3/bucket.rb:171:in `bucket_request'
  from /home/user_name/.rvm/gems/ruby-1.9.3-p484/gems/s3-0.3.11/lib/s3/object.rb:160:in `copy_object'
  from /home/user_name/.rvm/gems/ruby-1.9.3-p484/gems/s3-0.3.11/lib/s3/object.rb:98:in `copy'
  from (irb):53
  from /home/user_name/.rvm/gems/ruby-1.9.3-p484/gems/railties-3.2.16/lib/rails/commands/console.rb:47:in `start'
  from /home/user_name/.rvm/gems/ruby-1.9.3-p484/gems/railties-3.2.16/lib/rails/commands/console.rb:8:in `start'
  from /home/user_name/.rvm/gems/ruby-1.9.3-p484/gems/railties-3.2.16/lib/rails/commands.rb:41:in `<top (required)>'
  from script/rails:6:in `require'
  from script/rails:6:in `<main>'
1.9.3p484 :054 > s3_object_2 = artifact.attachment.bucket.objects.find("x y.pdf")
 => #<S3::Object:/my-bucket/x y.pdf> 
1.9.3p484 :055 > s3_object_2.copy(:key => "copy_of_file_2.pdf", :acl => :private)
 => #<S3::Object:/my-bucket/copy_of_file_2.pdf>

The data setup is proper, "a b.pdf" (note doublespaces) and "x y.pdf" files exist in the same bucket as artifact.attachment ("artifact" is a rails active record object)

qoobaa commented 10 years ago

Does it work with filenames without spaces?

k6s3 commented 10 years ago

Yes, it works with filenames without spaces..

Regards,

Kaushik Shah +91 9920 511 571

On Fri, Jan 24, 2014 at 3:13 PM, Kuba Kuźma notifications@github.comwrote:

Does it work with filenames without spaces?

— Reply to this email directly or view it on GitHubhttps://github.com/qoobaa/s3/issues/86#issuecomment-33209449 .

qoobaa commented 10 years ago

Hm. It seems like a problem with escaping strings when calculating signatures. Do you have some time to fix it?

k6s3 commented 10 years ago

Sure, I'll try to fix it over the next couple of days.

On Fri, Jan 24, 2014 at 3:45 PM, Kuba Kuźma notifications@github.comwrote:

Hm. It seems like a problem with escaping strings when calculating signatures. Do you have some time to fix it?

— Reply to this email directly or view it on GitHubhttps://github.com/qoobaa/s3/issues/86#issuecomment-33211408 .