How to integrate Paperclip and Mimetype-fu
First, a little background because there is a lot of interaction going on: I grab emails through Fetcher and process them with MMS2R to extract attachments. These attachments will usually be PDFs or MS Word documents, so you'd expect them to content-type
be application/pdf
and application/msword
accordingly, but unfortunately, it looks like a lot of email programs don't.
Instead, the attachments application/x-pdf
and application/x-doc
. I need them to be configured correctly so that scribd-fu documents the docs correctly. Now mimetype-fu will be able to figure out the correct content type, but for life I just can figure out how to set the paperclip'd attachment content type correctly.
Here's a snippet of code:
mms.process do |media_type, files|
# go through each file
files.each do |filename|
# if it a format we support, create a record
if media_type =~ /pdf/ # just pdfs for now, to reduce confusion
File.open(filename) do |tempfile|
# Somewhere in here I'd like to change filename.content_type
# to the proper type using mimetype-fu
# except doing tempfile.content_type = whatever doesn't seem to work.
thing = Thing.new
thing.document = tempfile
thing.save!
end
end
end
end
Any help would be appreciated as I was banging my head against the wall trying my best to try and make it work. I have tried these links already either without success or without grokking what to do:
- http://gist.github.com/55009/
- http://railsforum.com/viewtopic.php?id=27448
- http://github.com/dbackeus/paperclip/commit/a514bd03664fc6a764787f59c3169397336702b1
Thank you very much!
a source to share