Skip to content

Instantly share code, notes, and snippets.

@rtacconi
Created January 25, 2010 18:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rtacconi/286083 to your computer and use it in GitHub Desktop.
Save rtacconi/286083 to your computer and use it in GitHub Desktop.
# render a file (image, video) inside the browser
def inline
@video = Video.find(params[:id])
send_file @video.filepath.path, :type => @video.filepath_content_type
end
# force the browser to show the download modal box and send the file to the browser
# you can use the :xsendfile => true option
# send_file @video.filepath.path, :type => @video.filepath_content_type
def download
@video = Video.find(params[:id])
send_file @video.filepath.path, :type => @video.filepath_content_type, :xsendfile => true
end
# the code above con be used with paperclip plugin
# in your model write someth. like this
has_attached_file :filepath,
:url => APP_CONFIG['url']+"/videos/inline/:id",
:path => ":rails_root/uploads/:attachment/:id/:style/:basename.:extension"
# the path above is outside the public dir of the web server
# so, for the controller, you can control the access to file (security)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment