Created
February 22, 2012 20:04
-
-
Save fender21/1886923 to your computer and use it in GitHub Desktop.
Carrierwave
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 UploadedFile < CarrierWave::Uploader::Base | |
SEPARATOR = "\r\n".freeze | |
attr_reader :body | |
include CarrierWave::MimeTypes | |
process :set_content_type | |
def filename | |
@name = key | |
end | |
def extension_white_list | |
%w(pdf tiff tif) | |
end | |
def initialize(body) | |
@body = body | |
end | |
# return boundary data | |
def boundary | |
@body.lines.first.strip.gsub(/^-*/, '') | |
end | |
# return file content | |
def headers | |
headers = {} | |
@body.lines.each_with_index do |line, index| | |
next if index == 0 | |
break if line.strip == '' | |
key, value = *line.split(':') | |
headers[key.strip] = value.strip | |
end | |
headers | |
end | |
# stripts boundaty data and headers from the file content | |
def content | |
first_line_index = 0 | |
@body.lines.each do |line| | |
first_line_index += 1 | |
break if line.strip == '' | |
end | |
@body.lines.to_a[first_line_index..-2].join()[0..-3] | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment