Skip to content

Instantly share code, notes, and snippets.

@amitpatelx
Created June 24, 2016 14:14
Show Gist options
  • Save amitpatelx/74d31f5ba67f6c31169050123558b27a to your computer and use it in GitHub Desktop.
Save amitpatelx/74d31f5ba67f6c31169050123558b27a to your computer and use it in GitHub Desktop.
How to download images from different rails application sharing a session?
# This code is assumed to be part of one application(http://microservices2.btdashboard.com) sharing session with other(http://microservices1.btdashboard.com)
# '_your_app_session' is session_store key config in session_store.rb
# 'KzBxYy9jUURwbEYxR3ZCRmI3' is value of session cookie read in controller action
cookie = Mechanize::Cookie.new('_your_app_session', 'KzBxYy9jUURwbEYxR3ZCRmI3')
cookie.domain = ".btdashboard.com" # check domain config in session_store.rb
cookie.path='/' # Set as per your application settings
# More cookie settins as required
uri = URI.parse('http://microservices1.btdashboard.com')
agent = Mechanize.new
agent.cookie_jar.add(uri, cookie)
# Read it. You won't get 401
image = agent.get('http://microservices1.btdashboard.com/media/1/sample.png')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment