When attaching multipart entities of different encodings it is easy to get failures due to intermediary strings inside encode_multipart_form_data that care about encoding despite there being no need to care about them.
net-http-0.4.1/lib/net/http/generic_request.rb:354:in `block in encode_multipart_form_data': incompatible character encodings: UTF-8 and ASCII-8BIT (Encoding::CompatibilityError)
from /home/linus/.gem/ruby/3.3.3/gems/net-http-0.4.1/lib/net/http/generic_request.rb:320:in `each'
from /home/linus/.gem/ruby/3.3.3/gems/net-http-0.4.1/lib/net/http/generic_request.rb:320:in `encode_multipart_form_data'
from /home/linus/.gem/ruby/3.3.3/gems/net-http-0.4.1/lib/net/http/generic_request.rb:303:in `send_request_with_body_data'
from /home/linus/.gem/ruby/3.3.3/gems/net-http-0.4.1/lib/net/http/generic_request.rb:204:in `exec'
[...]
There are real use cases that are reasonable like posting both a text file and a pdf at the same time.
A workaround is to always encode absolutely everything as ascii-8bit before posting it.
When attaching multipart entities of different encodings it is easy to get failures due to intermediary strings inside
encode_multipart_form_data
that care about encoding despite there being no need to care about them.Example:
This results in
There are real use cases that are reasonable like posting both a text file and a pdf at the same time.
A workaround is to always encode absolutely everything as ascii-8bit before posting it.