【问题标题】:what is the replacement for module ActionController::UploadedFile?模块 ActionController::UploadedFile 的替代品是什么?
【发布时间】:2023-03-27 23:17:01
【问题描述】:

我一直在尝试获取 docraptor rails 示例以使用 Rails 3.0.7 将我生成的 PDF 保存到 Amazon S3。 ActionController::UploadedFile 似乎已被 ActionDispatch::Http::UploadedFile 取代,但当我尝试使用该类扩展我的文件对象时,我收到错误 'wrong argument type Class (expected Module)'

这里是来源。我是否错误地使用了“扩展”?我怎样才能做我想做的事情?真的,我要做的就是指定使用 Paperclip 上传到 S3 的文件的名称。

def create_pdfdoc(document_content)
  DocRaptor.create(  :document_content => document_content, 
                     :document_type    => 'pdf',
                     :name             => self.title.tr(' ','_'),
                     :test             => true) do |file, response|

      file.extend(ActionDispatch::Http::UploadedFile)
      file.content_type  = response.headers["content-type"]
      name = self.title.strip.gsub(/\s/, "_").gsub(/\W/, "").underscore.downcase
      file.original_filename = "#{name}.pdf"

      if response.code == 200
        self.pdfdoc = file
      end
  end
end

【问题讨论】:

  • 最后,我把它装袋了。我将一个局部变量设置为我要保存的文件的名称(self.pdfdoc),其余的由回形针处理。成功了。

标签: ruby-on-rails ruby paperclip


【解决方案1】:

最后,我只是把它装袋了。我将一个局部变量设置为我要保存的文件的名称(self.pdfdoc),其余的由回形针处理。成功了。

【讨论】:

    【解决方案2】:

    3 年后再回答一个问题……

    对于以后遇到这种情况的人来说,这是“正确”的做法:

    DocRaptor.create(options) do |file, response|
       upload = ActionDispatch::Http::UploadedFile.new({
          :filename => 'test.pdf',
          :type => response.headers["content-type"],
          :tempfile => file
        })
    end
    

    【讨论】:

      猜你喜欢
      • 2011-03-12
      • 1970-01-01
      • 2019-02-22
      • 2011-05-07
      • 2012-04-24
      • 2019-12-03
      • 2010-09-17
      • 2012-03-27
      • 2012-09-30
      相关资源
      最近更新 更多