Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ruby] Use Marcel to detect content-type in form-data file upload using faraday #18243

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions CI/circle_parallel.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ if [ "$NODE_INDEX" = "1" ]; then
echo "Running node $NODE_INDEX ..."
java -version

sudo apt-get -y install cpanminus libmagic-dev
sudo apt-get -y install cpanminus

(cd samples/client/petstore/perl && /bin/bash ./test.bash)
(cd samples/client/petstore/ruby && mvn integration-test)
Expand Down Expand Up @@ -112,5 +112,3 @@ else
(cd samples/client/petstore/java/apache-httpclient && mvn integration-test)

fi


Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ require 'typhoeus'
{{#isFaraday}}
require 'faraday'
require 'faraday/multipart' if Gem::Version.new(Faraday::VERSION) >= Gem::Version.new('2.0')
require 'filemagic'
require 'marcel'
{{/isFaraday}}
{{#isHttpx}}
require 'httpx'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,7 @@
form_params.each do |key, value|
case value
when ::File, ::Tempfile
filemagic = FileMagic.new(FileMagic::MAGIC_MIME)
data[key] = Faraday::FilePart.new(value.path, filemagic.file(value.path, true))
data[key] = Faraday::FilePart.new(value.path, Marcel::MimeType.for(Pathname.new(value.path)))
when ::Array, nil
# let Faraday handle Array and nil parameters
data[key] = value
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Gem::Specification.new do |s|
{{#isFaraday}}
s.add_runtime_dependency 'faraday', '>= 1.0.1', '< 3.0'
s.add_runtime_dependency 'faraday-multipart'
s.add_runtime_dependency 'ruby-filemagic'
s.add_runtime_dependency 'marcel'
{{/isFaraday}}
{{#isTyphoeus}}
s.add_runtime_dependency 'typhoeus', '~> 1.0', '>= 1.0.1'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
require 'time'
require 'faraday'
require 'faraday/multipart' if Gem::Version.new(Faraday::VERSION) >= Gem::Version.new('2.0')
require 'filemagic'
require 'marcel'


module OpenapiClient
Expand Down Expand Up @@ -141,8 +141,7 @@ def build_request_body(header_params, form_params, body)
form_params.each do |key, value|
case value
when ::File, ::Tempfile
filemagic = FileMagic.new(FileMagic::MAGIC_MIME)
data[key] = Faraday::FilePart.new(value.path, filemagic.file(value.path, true))
data[key] = Faraday::FilePart.new(value.path, Marcel::MimeType.for(Pathname.new(value.path)))
when ::Array, nil
# let Faraday handle Array and nil parameters
data[key] = value
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ Gem::Specification.new do |s|

s.add_runtime_dependency 'faraday', '>= 1.0.1', '< 3.0'
s.add_runtime_dependency 'faraday-multipart'
s.add_runtime_dependency 'ruby-filemagic'
s.add_runtime_dependency 'marcel'

s.add_development_dependency 'rspec', '~> 3.6', '>= 3.6.0'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
require 'time'
require 'faraday'
require 'faraday/multipart' if Gem::Version.new(Faraday::VERSION) >= Gem::Version.new('2.0')
require 'filemagic'
require 'marcel'


module Petstore
Expand Down Expand Up @@ -141,8 +141,7 @@ def build_request_body(header_params, form_params, body)
form_params.each do |key, value|
case value
when ::File, ::Tempfile
filemagic = FileMagic.new(FileMagic::MAGIC_MIME)
data[key] = Faraday::FilePart.new(value.path, filemagic.file(value.path, true))
data[key] = Faraday::FilePart.new(value.path, Marcel::MimeType.for(Pathname.new(value.path)))
when ::Array, nil
# let Faraday handle Array and nil parameters
data[key] = value
Expand Down
2 changes: 1 addition & 1 deletion samples/client/petstore/ruby-faraday/petstore.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ Gem::Specification.new do |s|

s.add_runtime_dependency 'faraday', '>= 1.0.1', '< 3.0'
s.add_runtime_dependency 'faraday-multipart'
s.add_runtime_dependency 'ruby-filemagic'
s.add_runtime_dependency 'marcel'

s.add_development_dependency 'rspec', '~> 3.6', '>= 3.6.0'

Expand Down
Loading