如何整合Paperclip和Mimetype-fu

时间:2009-05-07 18:45:19

标签: ruby-on-rails paperclip

首先,一点背景,因为有很多交互正在进行:我通过Fetcher抓取电子邮件,并使用MMS2R处理它们以提取附件。这些附件通常是PDF文件或MS Word文档,因此您希望他们的content-type分别为application/pdfapplication/msword,但不幸的是,许多邮件程序似乎都是不要这样做。

相反,附件是application/x-pdfapplication/x-doc。我需要正确设置这些,以便scribd-fu将正确iPaper文件。现在,mimetype-fu将设法找出正确的内容类型,但对于我的生活,我只能弄清楚如何正确设置回形针附件的内容类型。

以下是代码片段:

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

任何帮助都会受到赞赏,因为我一直在靠墙试图尝试各种各样的事情来试图让这个工作。我已经尝试过这些链接,但要么没有成功,要么没有了解需要做什么:

非常感谢!

1 个答案:

答案 0 :(得分:1)

你能做到吗

thing.document_content_type = whatever

或者你正在写文件=或其他什么?