Sha256: 73e09deeb3374772920a5f18d1a2a228716624a0fbb2a1436e9f5b820bc72089
Contents?: true
Size: 1.28 KB
Versions: 2
Compression:
Stored size: 1.28 KB
Contents
require 'action_dispatch/http/request' module ActionDispatch class PluploadParamsRenamer def initialize(app) @app = app end def call(env) req = Rack::Request.new(env) form_hash = Rails.version < "3.1" ? req.POST : env['rack.request.form_hash'] form_hash ||= {} if form_hash["_plupload_upload"] object, method = form_hash["_plupload_upload"].split(/[\[\]]/) submethod = form_hash["_plupload_upload"].split(/[\[\]]/)[-1] form_hash[object] ||= {} if form_hash["_plupload_files"] form_hash[object][method] = [] form_hash["_plupload_files"].each_with_index do |file, i| plupload_temp_path = "tmp/plupload-rails3/#{File.basename(file)}" FileUtils.mv(plupload_temp_path, file) original_filename = form_hash["_plupload_original_names"][i] content_type = form_hash["_plupload_content_types"][i] uploaded_file = ActionDispatch::Http::UploadedFile.new(:tempfile=>File.new(file), :content_type=>content_type, :filename=>original_filename) form_hash[object][method] << {submethod=>uploaded_file} end else form_hash[object][method] = form_hash["file"] end end @app.call(env) end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
plupload-rails3-0.0.5 | lib/app/middleware/plupload_params_renamer.rb |
plupload-rails3-0.0.4 | lib/app/middleware/plupload_params_renamer.rb |