Created
April 20, 2010 19:57
-
-
Save pmarreck/372976 to your computer and use it in GitHub Desktop.
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
require 'digest/sha1' | |
require 'tempfile' | |
class LocalPaperclipTempfile < ::Tempfile | |
# note: had a ton of trouble using "data" instead of "tmp_data" for naming here: | |
def initialize(filename, tmp_data, tmpdir = Dir::tmpdir) | |
@original_filename = filename | |
@tmp_data = tmp_data | |
super Digest::SHA1.hexdigest(@tmp_data), tmpdir | |
scribe | |
end | |
def scribe | |
self.sync = true | |
self.binmode | |
self.write @tmp_data | |
self.rewind | |
self | |
end | |
def original_filename | |
@original_filename | |
end | |
def content_type | |
begin | |
mime = `file --mime -br #{self.path}`.strip | |
mime = mime.gsub(/^.*: */,"") | |
mime = mime.gsub(/;.*$/,"") | |
mime = mime.gsub(/,.*$/,"") | |
rescue | |
mime = "image/png" # don't really like the dependency on the 'file' command... | |
end | |
mime | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment