I am using the official AWS ruby gem for S3 and I am having trouble using the "url_for" method on files that have special characters in them (ie. commas, apostrophes). I am using the latest aws-sdk gem for ruby and my code looks like this:
s3 = AWS::S3::new
bucket = s3.buckets[bucket]
object = bucket.objects[object_address]
object_url = object.url_for(:read, :expires => 60*60, :secure => true)
The object is getting found correctly, but the URL I get from url_for gives me a HTTPError: 404 Not Found error. It works fine if the filename doesn't have commas or apostrophes in it.
Is there a way to handle this without needing to restrict the filenames in the first place?
Are you escaping the URL string by default? For example:
object_url = CGI.escape(object.url_for(:read, :expires => 60*60, :secure => true))
This would properly escape the string into a browser-readable format. I do this for all of my secure S3 URL's since there are sometimes a /
or +
character in the signature that will cause the link to fail as well if it's not properly escaped. This will also escape the commas and apostrophes properly.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With