Reputation: 5978
I want to access the request object before a file upload gets converted into a tempfile and add it to a queue to be processed later, mainly because IO objects can't be marshaled or serialized. How can I do this?
I'll also need to "redo" the request at later point. At what point in the rails request lifecycle would I hook into to do this?
Upvotes: 2
Views: 398
Reputation: 5978
Code example, in routes.rb:
post 'incoming_email' => Proc.new { |env|
RequestCache.create!(
data: env['rack.input'].read,
content_type: env['CONTENT_TYPE'],
content_length: env['CONTENT_LENGTH']
)
[200, {'Content-Type' => 'text/plain'}, ['OK']]
}
and in the model:
class RequestCache < ActiveRecord::Base
attr_accessible :data, :content_length, :content_type
def params
Rack::Request.new({
'rack.input' => StringIO.new(data),
'CONTENT_LENGTH' => content_length,
'CONTENT_TYPE' => content_type
}).POST
end
end
Upvotes: 2
Reputation: 4766
Well, just to do this you don't do something complicated like that.
If you want to do upload in the background process, you could simply use delayed_paperclip. This gem use delayed_job and process upload, resize, send to s3 (if you want) in the background process.
Upvotes: 1