Question

First, a little background, because there is a lot of interaction going on: I'm grabbing emails via Fetcher, and processing them using MMS2R to extract the attachments. These attachments are generally going to be PDF files or MS Word documents, so you'd expect that their content-type would be application/pdf and application/msword respectively, but unfortunately it appears that many mail programs do not do this.

Instead, the attachments are application/x-pdf and application/x-doc. I need these to be set correctly so that scribd-fu will properly iPaper the documents. Now, mimetype-fu will manage to figure out the proper content-type, but for the life of me, I just can figure out how to properly set the content-type of the paperclip'd attachment.

Here's a snippet of the code:

mms.process do |media_type, files|
  # go through each file
  files.each do |filename|
    # if it's 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, because I've been beating my head against a wall trying all manner of things to try to get this working. I've tried these links already either without success or without grokking what needs doing:

Thanks greatly!

Was it helpful?

Solution

Can you just do

thing.document_content_type = whatever

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top