Paperclip functionality based on https://github.com/thoughtbot/paperclip