Created
April 1, 2016 07:50
-
-
Save verbaleks/b8eb0364959778e14a28a8e514b801ad to your computer and use it in GitHub Desktop.
Paperclip handler for Hashie::Mash and Hash (Grape API)
This file contains hidden or 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
module Paperclip | |
class HashieMashUploadedFileAdapter < AbstractAdapter | |
attr_accessor :original_filename # use this accessor if you have paperclip version < 3.3.0 | |
def initialize(target) | |
@tempfile, @content_type, @size = target.tempfile, target.type, target.tempfile.size | |
self.original_filename = target.filename | |
end | |
end | |
class HashUploadedFileAdapter < AbstractAdapter | |
attr_accessor :original_filename # use this accessor if you have paperclip version < 3.3.0 | |
def initialize(target) | |
@tempfile, @content_type, @size = target[:tempfile], target[:type], target[:tempfile].size | |
self.original_filename = target[:filename] | |
end | |
end | |
end | |
Paperclip.io_adapters.register Paperclip::HashieMashUploadedFileAdapter do |target| | |
target.is_a? Hashie::Mash | |
end | |
Paperclip.io_adapters.register Paperclip::HashUploadedFileAdapter do |target| | |
target.is_a?(Hash) && target[:tempfile].is_a?(Tempfile) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment