私はちょうど2日を費やしてこれをやろうとしましたが、やっとそれを理解しました。 jsonにシリアル化できるように、Base64でファイルをエンコードする必要があります。次に、あなたが労働者にそれをデコードして作成する必要が新しい
ActionDispatch::Http::UploadedFile
ここ
エンコードとresqueに渡す方法は次のとおりです。
// You only need to encode the actual file, everything else in the
// ActionDispatch::Http::UploadedFile object is just string or a hash of strings
file = params[:file] // Your ActionDispatch::Http::UploadedFile object
file.tempfile.binmode
file.tempfile = Base64.encode64(file.tempfile.read)
Resque.enqueue(QueueWorker, params)
を、ここでデコードして、内のオブジェクトに戻って変換する方法ですあなたの労働者
class QueueWorker
@queue = :main_queue
def self.perform(params)
file = params['file']
tempfile = Tempfile.new('file')
tempfile.binmode
tempfile.write(Base64.decode64(file['tempfile']))
// Now that the file is decoded you need to build a new
// ActionDispatch::Http::UploadedFile with the decoded tempfile and the other
// attritubes you passed in.
file = ActionDispatch::Http::UploadedFile.new(tempfile: tempfile, filename: file['original_filename'], type: file['content_type'], head: file['headers'])
// This object is now the same as the one in your controller in params[:file]
end
end
唯一の方法のようです。私はちょうど処理する前にファイルの移動を処理し、後で削除することを望んでいませんでした。ありがとう。 –