one-sdk-js icon indicating copy to clipboard operation
one-sdk-js copied to clipboard

[BUG] Not possible to send form-data with duplicate key names

Open jnv opened this issue 3 years ago • 0 comments

Based on https://github.com/superfaceai/station/issues/242

Mailgun in particular expects email attachments to be submitted under attachment fields in multipart/form-data. However, we don't allow duplicated keys to be sent in body, because it is treated as a JS object.

Possible workaround would be to detect array in value when constructing the FormData object, and append each value individually.

https://github.com/superfaceai/one-sdk-js/blob/1f03560419ab141382d02b5cc51e17aa14365ca4/src/lib/fetch.ts#L192-L194

This makes sense because there isn't any official way to serialize array values in FormData.

Therefore the following Comlink:

body {
  attachment = [bufferA, bufferB]
}

Results in:

attachment=bufferA
attachment=bufferB

jnv avatar May 12 '22 10:05 jnv