Created
October 4, 2017 01:16
-
-
Save walterdavis/4dc6513d331fb5b6b343447d9d9b708c to your computer and use it in GitHub Desktop.
Shrine setup
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
include FileUploader::Attachment.new(:file) |
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
... | |
<%= f.check_box :parse, label: (document.file.present? && document.file[:original].exists? ? document.file[:original].original_filename : 'Attached file') %> | |
... |
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
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 |
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
class RawUploader < Shrine | |
plugin :remove_attachment | |
end |
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
include RawUploader::Attachment.new(:cv) |
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
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The users (with the raw_uploader) work perfectly, but the documents (with the file_uploader) give me the shrine tempfile name instead.