Skip to content
This repository was archived by the owner on Jan 26, 2025. It is now read-only.

Commit 5f8bb59

Browse files
author
Sammy Larbi
committed
really merge rails3.1 fix for the middleware
1 parent 80108c3 commit 5f8bb59

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,35 @@
1+
require 'action_dispatch/http/request'
2+
module ActionDispatch
3+
class PluploadParamsRenamer
4+
def initialize(app)
5+
@app = app
6+
end
7+
8+
def call(env)
9+
req = Rack::Request.new(env)
10+
if req.POST["_plupload_upload"]
11+
object, method = req.params["_plupload_upload"].split(/[\[\]]/)
12+
submethod = req.params["_plupload_upload"].split(/[\[\]]/)[-1]
13+
req.params[object] ||= {}
14+
if req.POST["_plupload_files"]
15+
req.params[object][method] = []
16+
req.POST["_plupload_files"].each_with_index do |file, i|
17+
plupload_temp_path = "tmp/plupload-rails3/#{File.basename(file)}"
18+
FileUtils.mv(plupload_temp_path, file)
19+
20+
original_filename = req.POST["_plupload_original_names"][i]
21+
content_type = req.POST["_plupload_content_types"][i]
22+
23+
uploaded_file = ActionDispatch::Http::UploadedFile.new(:tempfile=>File.new(file), :content_type=>content_type, :filename=>original_filename)
24+
25+
req.params[object][method] << {submethod=>uploaded_file}
26+
end
27+
else
28+
req.params[object][method] = req.params["file"]
29+
end
30+
end
31+
32+
@app.call(env)
33+
end
134
end
235
end

0 commit comments

Comments
 (0)