attachment :file, uploader: FileUploader module SelectedAction def select_action_by_params params # skip action table lookups for current revision rev_id = params[:rev_id] super unless rev_id && rev_id == last_content_action_id end def last_content_action_id # find action id from content (saves lookups) db_content.to_s.split(/[\/\.]/)[1] end end include SelectedAction format do view :source do |args| card.attachment.url end view :core do |args| handle_source args do |source| card_url source end end def handle_source args source = _render_source args source ? yield( source ) : '' rescue 'File Error' end end format :file do view :core do |args| # returns send_file args. not in love with this... if format = card.attachment_format( params[:format] ) # this means we only support known formats. dislike. if params[:explicit_file] and r = controller.response r.headers["Expires"] = 1.year.from_now.httpdate #r.headers["Cache-Control"] = "public" # currently using default "private", because proxy servers could block needed permission checks end # elsif ![format, 'file'].member? params[:format] # formerly supported redirecting to correct file format # return redirect_to( request.fullpath.sub( /\.#{params[:format]}\b/, '.' + format ) ) #card.attachment.url(style) ) file = selected_file_version [ file.path, { type: file.content_type, filename: "#{card.cardname.safe_key}#{file.extension}", x_sendfile: true, disposition: (params[:format]=='file' ? 'attachment' : 'inline' ) } ] else _render_not_found end end def selected_file_version card.attachment end end format :html do view :core do |args| handle_source args do |source| "Download #{ showname args[:title] }" end end view :editor do |args| file_chooser args end def preview args '' end view :preview_editor, tags: :unknown_ok do |args| cached_upload_card_name = Card::Env.params[:attachment_upload] cached_upload_card_name.gsub!(/\[\w+\]$/, "[cached_upload]") <<-HTML
#{preview(args)} |
#{card.original_filename} |
#{number_to_human_size(card.attachment.size)} |