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:

Thank you very much!

0


a source to share


1 answer


Can you just do

thing.document_content_type = whatever

      



or are you doing your scribd-fu in doc = or something?

+1


a source







All Articles