Created
January 25, 2010 18:26
-
-
Save rtacconi/286083 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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