Skip to content

Instantly share code, notes, and snippets.

@walterdavis
Created October 4, 2017 01:16
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 walterdavis/4dc6513d331fb5b6b343447d9d9b708c to your computer and use it in GitHub Desktop.
Save walterdavis/4dc6513d331fb5b6b343447d9d9b708c to your computer and use it in GitHub Desktop.
Shrine setup
include FileUploader::Attachment.new(:file)
...
<%= f.check_box :parse, label: (document.file.present? && document.file[:original].exists? ? document.file[:original].original_filename : 'Attached file') %>
...
class FileUploader < Shrine
plugin :processing
plugin :versions
plugin :remove_attachment
process(:convert) do |io, context|
doc = begin
io[:original].download
rescue
io.download
end
output_html = Tempfile.new(%w[pandoc .md], binmode: true)
system *%W[pandoc #{doc.path} -t html5 -o #{output_html.path}]
output_html.open
context[:record].body_html = output_html.read
output_html.rewind
{ original: doc, html: output_html }
end
process(:store) do |io, context|
{original: io}
end
end
class RawUploader < Shrine
plugin :remove_attachment
end
include RawUploader::Attachment.new(:cv)
def download
temp = @user.cv.download
send_file temp, disposition: 'attachment', filename: @user.cv.original_filename,
type: @user.cv.mime_type, stream: true, buffer_size: 4096
end
@walterdavis
Copy link
Author

The users (with the raw_uploader) work perfectly, but the documents (with the file_uploader) give me the shrine tempfile name instead.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment