방금이 작업을 위해 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
유일한 방법 같습니다. 난 그냥 처리하기 전에 파일의 이동을 처리하고 나중에 삭제하고 싶지 않았어. 감사. –