HTTP Client and Content-Type: multipart/form-data and Content-Transfer-Encoding: base64
Hi community,
I’m working on a multipart/form-data POST
request using the IntelliJ HTTP Client. My goal is to send a file with the Content-Transfer-Encoding: base64
header.
Here’s how it works successfully with curl
:
curl --trace-ascii trace.log -H "Content-Type: multipart/form-data" -F "file=@archive.zip;encoder=base64;type=application/x-zip-compressed" "http://127.0.0.1/upload/"
This generates the following request:
POST /upload/ HTTP/1.1
Host: 127.0.0.1
User-Agent: curl/8.9.1
Accept: */*
Content-Length: 640035
Content-Type: multipart/form-data; boundary=--------------------
----iE11EjDWsC9QGLjXu5QlpN
--------------------------iE11EjDWsC9QGLjXu5QlpN
Content-Disposition: form-data; name="file"; filename="archive.zip"
Content-Type: application/x-zip-compressed
Content-Transfer-Encoding: base64
UEsDBAoAAAgAALV+eVkAAAAAAAAAAAAAAAAnAAAAa2F0YWxvZy1jb250ZW50LTAuMC4wLVNOQVBT
...
NTgvY2F0YWxvZ19WZXJnYWJldmVyZmFocmVuLnhtbFBLBQYAAAAAGAIYAgz4AAAU
KgYAAAA=
--------------------------iE11EjDWsC9QGLjXu5QlpN--
With the IntelliJ HTTP Client, I tried this:
POST http://127.0.0.1/upload/ HTTP/1.1
Content-Type: multipart/form-data; boundary=boundary
--boundary
Content-Disposition: form-data; name="file"; filename="archive.zip"
Content-Type: application/x-zip-compressed
Content-Transfer-Encoding: base64
< archive.zip
--boundary--
The Issue:
On the server side, I see this request from the IntelliJ HTTP Client:
user-agent=[IntelliJ HTTP Client/IntelliJ IDEA 2024.3],
accept-encoding=[br, deflate, gzip, x-gzip], accept=[*/*],
host=[localhost],
content-type=[multipart/form-data; boundary=6e61e87fb534e2fc],
content-length=[467759]
content-disposition: form-data; name="file"; filename="archive.zip"
content-length: 467510
content-type: application/x-zip-compressed
content-transfer-encoding: binary
The Content-Transfer-Encoding
header is rewritten as binary
, which doesn’t align with my expectation or match the behavior of curl
.
My Expectations:
- Ideally, the IntelliJ HTTP Client should support encoding the file as Base64 (like
curl
does withencoder=base64
). - At the very least, the HTTP Client should respect and pass through the
Content-Transfer-Encoding: base64
header as specified.
Question:
Does anyone know how to achieve Base64 encoding for multipart file uploads in IntelliJ HTTP Client? Is there a way to prevent it from rewriting the Content-Transfer-Encoding
header?
Any suggestions or insights would be greatly appreciated!
Please sign in to leave a comment.