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

Content-Disposition header overwrite fails #4

Open
spidzio opened this issue Apr 27, 2022 · 0 comments
Open

Content-Disposition header overwrite fails #4

spidzio opened this issue Apr 27, 2022 · 0 comments

Comments

@spidzio
Copy link

spidzio commented Apr 27, 2022

I am trying to overwrite the Content-Disposition header.

For the third party API, I need a very specific filename that includes /.
I noticed the Content-Disposition header is not entirely overwritten. It still adds the default name and filename.

require 'faraday'
require 'faraday/multipart'

connection = Faraday.new(url: 'http://localhost:3000') do |connection_builder|
  connection_builder.request :multipart
  connection_builder.response :logger, nil, { headers: true, bodies: true }
end

payload = { file: Faraday::Multipart::FilePart.new('test.txt', 'text/plain', nil, 'Content-Disposition' => 'form-data; name="file"; filename="foo/bar"') }

connection.post('path', payload)

It creates

Content-Disposition: form-data; name="file"; filename="foo/bar"; name="file"; filename="test.txt"

instead of

Content-Disposition: form-data; name="file"; filename="foo/bar"

I was also trying to give the file name as a parameter to the FilePart.new.

require 'faraday'
require 'faraday/multipart'

connection = Faraday.new(url: 'http://localhost:3000') do |connection_builder|
  connection_builder.request :multipart
  connection_builder.response :logger, nil, { headers: true, bodies: true }
end

payload = { file: Faraday::Multipart::FilePart.new('test.txt', 'text/plain', 'foo/bar') }

connection.post('path', payload)

It creates

Content-Disposition: form-data; name="file"; filename="bar"

while I need

Content-Disposition: form-data; name="file"; filename="foo/bar"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
1 participant