Skip to content

Client: Multipart upload doesn't work with some servers #5157

@hykilpikonna

Description

@hykilpikonna

elysiajs/elysia#1513

When Ktor sends a multipart form request, the name= field isn't quoted, which differs from the standard FormData behavior. Even though the standard didn't say they must be quoted strings, many server frameworks (e.g. elysia) expect it to be quoted, which causes elysia to ignore the field entirely.

Image

Packet capture: Note that the FormData sent name="photo" while Ktor sent name=photo

JS Fetch FormData

POST /upload HTTP/1.1
x-instant-key: meowmeow
Content-Type: multipart/form-data; boundary=-WebkitFormBoundary074b68ff41eb4ad0bc81501198ed9954
Connection: keep-alive
User-Agent: Bun/1.2.21
Accept: */*
Host: localhost:3000
Accept-Encoding: gzip, deflate, br, zstd
Content-Length: 9409403

---WebkitFormBoundary074b68ff41eb4ad0bc81501198ed9954
Content-Disposition: form-data; name="id"

test-252
---WebkitFormBoundary074b68ff41eb4ad0bc81501198ed9954
Content-Disposition: form-data; name="owner_key"

1234
---WebkitFormBoundary074b68ff41eb4ad0bc81501198ed9954
Content-Disposition: form-data; name="photo"; filename="./UWU01721.JPG"
Content-Type: application/octet-stream

�����AExif

Ktor

POST /upload HTTP/1.1
Host: 172.16.0.212:3000
Content-Length: 14279723
x-instant-key: meowmeow
Accept: application/json
Accept-Charset: UTF-8
User-Agent: ktor-client
Content-Type: multipart/form-data; boundary=-748f4c8e-19eb394f-6d6c679e-74278686658a4a8c701fae79636dfd85372e904c-4

---748f4c8e-19eb394f-6d6c679e-74278686658a4a8c701fae79636dfd85372e904c-4
Content-Disposition: form-data; name=id
Content-Length: 36

e662d915-3ed6-4042-baca-861630ab65bc
---748f4c8e-19eb394f-6d6c679e-74278686658a4a8c701fae79636dfd85372e904c-4
Content-Disposition: form-data; name=owner_key
Content-Length: 4

1234
---748f4c8e-19eb394f-6d6c679e-74278686658a4a8c701fae79636dfd85372e904c-4
Content-Disposition: form-data; name=photo; filename=UWU01955.JPG
Content-Type: image/jpeg
Content-Length: 14166893

���ῄExif

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions