flexera-public / right_aws

RightScale Amazon Web Services Ruby Gems
MIT License
451 stars 175 forks source link

Support to S3's GET link with response-* params #47

Closed yorkxin closed 13 years ago

yorkxin commented 13 years ago

Hi all,

I have added the response-* parameters support of S3 GET link. But as you can see my coding style is not pretty, neither did I run the unit test. But it works fine my project which needs this new feature provided by AWS, though. I hope that someone could improve these dirty codes. I did only tested the functionalities of response-cache-control and response-content-disposition; other parameters may or may not work.

In addition, some methods in lib/awsbase/support.rb were removed, and I just can't get the S3Interface work, so I added them back from 85cb08e0198cb3306d278a2ff42c09c1146436b7.

Thanks.

Yu-Cheng Chuang

Reference: http://docs.amazonwebservices.com/AmazonS3/latest/API/RESTObjectGET.html

yorkxin commented 13 years ago

Note: there is a bug when setting "response-content-disposition" => "attachment; filename=blahblah" with blahblah containing non-ascii characters (e.g. Chinese characters or Japanese Kana)

yorkxin commented 13 years ago

Sorry, I forgot the sample code.

As you can see, there is one additional parameter in get_link , so if you wanna generate a get_link with response-* parameters, you also need to specify expire and headers.

For example, assume that s3instance is an instance of RightAws::S3Interface :

# Traditional way, without headers and response-* params
s3instance.get_link('bucket_name', 'key/song.mp3', 86400)
#=> https://bucket_name.s3.amazonaws.com:443/key%2Fsong.mp3?Signature=vIh5...&Expires=1296611902&AWSAccessKeyId=AK...

# To generate url with response-* params, headers parameter must be specified,
# and response-* params are in hash style
s3instance.get_link('bucket_name', 'key/song.mp3', 86400, 
  {}, # empty additional headers
  {
    "response-content-disposition" => "attachment; filename=good_song.mp3", # specify Content-disposition and filename
    "response-cache-control"=>"No-cache" # specify Cache-control
  }
)
#=> https://bucket_name.s3.amazonaws.com:443/key%2Fsong.mp3?response-cache-control=No-cache&response-content-disposition=attachment; filename=good_song.mp3&Signature=7TLD...&Expires=1296611902&AWSAccessKeyId=AK...
yorkxin commented 13 years ago

Hi all,

I have another commit which resolves the non-ascii filename issue, along with documents on how to generate GetObject link with response-* parameters.

Hope that it's helpful for you.

Yu-Cheng Chuang

rbroemeling commented 13 years ago

Hi chitsaou,

Thanks for doing the work on this! I've rewritten your patches quite thoroughly, cleaning them up as you asked. The cleaned up version is available here: https://github.com/rightscale/right_aws/pull/63

Thanks,

Remi

yorkxin commented 13 years ago

Hi Remi:

Thanks, your implementation is better than mine. I'll close my request :)

Yu-Cheng