This feels like it should be simple, but after Googling for an hour I can't figure this out.
I'm POSTing an Amazon S3 'policy document' as JSON to my server. I need to encode the JSON as is, but Rails is adding stuff to 'params' which is cluttering the JSON I need to encode.
Here is what I have:
class Api::Amazons3Controller < Api::BaseController
def sign_policy
policy_document = params.except(:action, :controller)
encoded_policy_document = Base64.encode64(policy_document.to_json).gsub(/\n|\r/, '')
signature = Base64.encode64(
OpenSSL::HMAC.digest(
OpenSSL::Digest::Digest.new('sha1'),
ENV['AWS_SECRET_ACCESS_KEY'],
policy_document)
).gsub(/\n/, '')
response = { policy: policy_document, signature: signature }
render json: response
end
end
I'm trying to 'clean up' the params with params.except(:action, :controller), but policy_document.to_json adds a root note called 'amazons3' (the controller name) around the JSON, which I don't want. I just need to encode the pure json from the request.
Any help would be highly appreciated!