开发者

Ruby AWS::S3::S3Object.find always returns NoSuchKey exception

开发者 https://www.devze.com 2023-03-03 13:22 出处:网络
I am trying to test for the existence of an image before I attempt to get its url, because if I just used the \"url_for\" method that it does not throw an error in the event that a resource is not ava

I am trying to test for the existence of an image before I attempt to get its url, because if I just used the "url_for" method that it does not throw an error in the event that a resource is not available.

However, I can get a valid url from url_for, but I get a NoSuchKey exception using the 开发者_StackOverflow社区"find" method with the EXACT SAME PARAMETERS. This is taking too long. Does this just plain not work?

Update: Switched to AWS-S3, now using code below:

bucket = "my_amazon_bucket"
key = "my_amazon_key"

begin
  s3 = RightAws::S3Interface.new(AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY)
  # This will trigger the exception if this image doesn't exist.
  s3.head(bucket,key)
  retval = s3.get_link(bucket,key)
rescue RightAws::AwsError => bang
  puts bang.message + ": #{bucket} : #{key}"
end


I struggled with the 'aws-s3' gem. Seems old and unsupported. I'm having a much better time with the 'S3' gem:

https://github.com/qoobaa/s3

Others are using 'right_aws'

https://github.com/rightscale/right_aws

0

精彩评论

暂无评论...
验证码 换一张
取 消