Rails signature does not match amazon s3

I had uploads to Amazon s3 working with AngularJS and NodeJS but now am using Rails as the backend. So I figured all I'd have to do is translade NodeJS code to Rails. Source: https://github.com/nukulb/s3-angular-file-upload/blob/master/lib/controllers/aws.js

and my conversion:

def aws_signature

        mime_type = "image/jpeg"
    expiration = Date.new(Time.now.year + 1, 01, 01) #Time.now.utc.strftime('%Y/%m/%d %H:%M:%S+00:00')

        s3_policy = {
         expiration: expiration,
         conditions: [
          ['starts-with', '$key', '/'],
          {bucket: ENV["BUCKET"] },
          {acl: 'public-read'},
          ['starts-with', '$Content-Type', mime_type],
          {success_action_status: '201'}
          ]
        }
                    puts s3_policy.inspect
        string_policy = s3_policy.to_json
                    puts string_policy.inspect
        base64_policy = URI.escape(Base64.encode64(string_policy).strip)
              puts base64_policy.inspect
        digest = OpenSSL::Digest::Digest.new('sha1')
        signature = OpenSSL::HMAC.digest(digest, ENV["S3_SECRET"], base64_policy)
              puts signature.inspect


        s3_credentials = {
            s3Policy: base64_policy,
            s3Signature: signature,
            AWSAccessKeyId: ENV["S3_KEY"]
 }

        render json: s3_credentials
    end

Now I am getting a 304 response from Amazon with SignatureDoesNotMatch in xml.

Did I miss something in the conversion to rails code? Is there a way to compare the unencrypted params received in amazon?