qoobaa / s3

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

temporary_url method throws URI::InvalidURIError or an AWS SignatureDoesNotMatch #51

Open empika opened 13 years ago

empika commented 13 years ago

Hi

I'm trying to generate a temporary URL for a bucket object:

s.bucket_items[5].temporary_url

But I get the error:

URI::InvalidURIError: bad URI(is not URI?): /files/file.text

It looks like the temporary_url method needs to pass the host param to Signature.generate_temporary_url_signature:

def temporary_url(expires_at = Time.now + 3600)
      uri = URI.parse(self.url)
      signature = Signature.generate_temporary_url_signature(:bucket => name,
                                                             :resource => URI.escape(key),
                                                             :expires_at => expires_at,
                                                             :secret_access_key => secret_access_key,
                                                             :host => uri.host)

      "#{url}?AWSAccessKeyId=#{self.bucket.service.access_key_id}&Expires=#{expires_at.to_i.to_s}&Signature=#{signature}"
end

However this does not fix the problem. Any URLs generated with this will throw a SignatureDoesNotMatch from Amazon. I've looked for AWS docs on how to generate signed expiring URL's but cant find any.

Any ideas on how to fix this issue?

Cheers