Skip to content

Instantly share code, notes, and snippets.

@cmattson
Last active December 19, 2015 08:19
Show Gist options
  • Save cmattson/5924864 to your computer and use it in GitHub Desktop.
Save cmattson/5924864 to your computer and use it in GitHub Desktop.
Ruby version of Rackspace's example form signing code. Full details on Cloud Files FormPost capability are in the API docs: http://docs.rackspace.com/files/api/v1/cf-devguide/content/FormPost-d1a555.html sprintf is used here because it breaks across multiple lines nicely; there's nothing stopping you from using inline interpolation (heck, or con…
require 'openssl'
path = '/v1/account/container/object_prefix'
redirect = 'https://myserver.com/some-page'
max_file_size = 104857600
max_file_count = 10
expires = (Time.now.to_i + 600)
key = 'mykey'
hmac_body = sprintf("%s\n%s\n%s\n%s\n%s", path, redirect, max_file_size, max_file_count, expires)
signature = OpenSSL::HMAC.hexdigest('sha1', key, hmac_body)
@cmattson
Copy link
Author

cmattson commented Sep 7, 2013

The formatting in the description committed suicide for some reason.

Relevant API docs are here:
http://docs.rackspace.com/files/api/v1/cf-devguide/content/FormPost-d1a555.html

sprintf is used for the most similarity with the Rackspace sample code (without being weird and using String#%) and because it breaks nicely across multiple lines. If you really want to use % for maximum simulacrum status, it takes an array.

@johndavid400
Copy link

works great.. thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment