I just spent two days trying to do this, and finally figured it out. You need Base64 to encode the file so that it can be serialized in json. Then you need to decode it in the working file and create a new
ActionDispatch::Http::UploadedFile
Here's how to encode and pass in resque:
file = params[:file]
file.tempfile.binmode
file.tempfile = Base64.encode64(file.tempfile.read)
Resque.enqueue(QueueWorker, params)
And here's how to decode and convert back to an object inside your worker
class QueueWorker
@queue = :main_queue
def self.perform(params)
file = params['file']
tempfile = Tempfile.new('file')
tempfile.binmode
tempfile.write(Base64.decode64(file['tempfile']))
file = ActionDispatch::Http::UploadedFile.new(tempfile: tempfile, filename: file['original_filename'], type: file['content_type'], head: file['headers'])
end
end
source
share