Commit 0460c1bb authored by Rémy Coutable's avatar Rémy Coutable Committed by Douglas Barbosa Alexandre

Merge branch 'multipart-uploaded-file' into 'master'

Inject ::UploadedFile from Multipart middleware

Closes #25888

See merge request !8215
parent d4376e0c
...@@ -42,7 +42,7 @@ module Gitlab ...@@ -42,7 +42,7 @@ module Gitlab
key, value = parsed_field.first key, value = parsed_field.first
if value.nil? if value.nil?
value = File.open(tmp_path) value = open_file(tmp_path)
@open_files << value @open_files << value
else else
value = decorate_params_value(value, @request.params[key], tmp_path) value = decorate_params_value(value, @request.params[key], tmp_path)
...@@ -68,7 +68,7 @@ module Gitlab ...@@ -68,7 +68,7 @@ module Gitlab
case path_value case path_value
when nil when nil
value_hash[path_key] = File.open(tmp_path) value_hash[path_key] = open_file(tmp_path)
@open_files << value_hash[path_key] @open_files << value_hash[path_key]
value_hash value_hash
when Hash when Hash
...@@ -78,6 +78,10 @@ module Gitlab ...@@ -78,6 +78,10 @@ module Gitlab
raise "unexpected path value: #{path_value.inspect}" raise "unexpected path value: #{path_value.inspect}"
end end
end end
def open_file(path)
::UploadedFile.new(path, File.basename(path), 'application/octet-stream')
end
end end
def initialize(app) def initialize(app)
......
...@@ -12,7 +12,7 @@ describe Gitlab::Middleware::Multipart do ...@@ -12,7 +12,7 @@ describe Gitlab::Middleware::Multipart do
expect(app).to receive(:call) do |env| expect(app).to receive(:call) do |env|
file = Rack::Request.new(env).params['file'] file = Rack::Request.new(env).params['file']
expect(file).to be_a(File) expect(file).to be_a(::UploadedFile)
expect(file.path).to eq(tempfile.path) expect(file.path).to eq(tempfile.path)
end end
...@@ -39,7 +39,7 @@ describe Gitlab::Middleware::Multipart do ...@@ -39,7 +39,7 @@ describe Gitlab::Middleware::Multipart do
expect(app).to receive(:call) do |env| expect(app).to receive(:call) do |env|
file = Rack::Request.new(env).params['user']['avatar'] file = Rack::Request.new(env).params['user']['avatar']
expect(file).to be_a(File) expect(file).to be_a(::UploadedFile)
expect(file.path).to eq(tempfile.path) expect(file.path).to eq(tempfile.path)
end end
...@@ -54,7 +54,7 @@ describe Gitlab::Middleware::Multipart do ...@@ -54,7 +54,7 @@ describe Gitlab::Middleware::Multipart do
expect(app).to receive(:call) do |env| expect(app).to receive(:call) do |env|
file = Rack::Request.new(env).params['project']['milestone']['themesong'] file = Rack::Request.new(env).params['project']['milestone']['themesong']
expect(file).to be_a(File) expect(file).to be_a(::UploadedFile)
expect(file.path).to eq(tempfile.path) expect(file.path).to eq(tempfile.path)
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment