Guest User

Untitled

a guest
Feb 20th, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.71 KB | None | 0 0
  1. class Files < Application
  2.  
  3. def mp3audio
  4. nginx_send_file("/protected/matz_cant_patch.mp3")
  5. end
  6.  
  7. def image
  8. nginx_send_file("/protected/sirens_of_the_sea.jpg")
  9. end
  10.  
  11. # This is gonna be in merb-core 0.9.8, version in 0.9.7 does
  12. # not take care of content type and content disposition headers
  13. # at all so it's not very useful and may be confusing for some.
  14. def nginx_send_file(path, content_type = "")
  15. # Let Nginx detect content type unless it is explicitly set
  16. headers['Content-Type'] = content_type
  17. headers["Content-Disposition"] ||= "attachment; filename=#{path.split('/').last}"
  18.  
  19. headers['X-Accel-Redirect'] = path
  20.  
  21. return ' '
  22. end
  23. end
Add Comment
Please, Sign In to add comment