#822·colly

Multipart body should not be `map[string][]byte`

Author: abiriadevCreated Jul 25, 2024Updated Jul 15, 2025

First of all, thanks for the wonderful project! colly has saved our team a lot of time!!

Context

ref: #8, #33

According to RFC7578 section 4.3:

4.3. Multiple Files for One Form Field

The form data for a form field might include multiple files. [RFC2388] suggested that multiple files for a single form field be transmitted using a nested "multipart/mixed" part. This usage is deprecated.

To match widely deployed implementations, multiple files MUST be sent by supplying each file in a separate part but all with the same "name" parameter.

Receiving applications intended for wide applicability (e.g., multipart/form-data parsing libraries) SHOULD also support the older method of supplying multiple files.

and this practice is unsurprisingly common, and I am facing the exact same case.

The issue

The name field does not have to be unique. There are few common cases when a duplicated name field is required (e.g., when uploading an array of files), and this case should be properly covered.

https://github.com/gocolly/colly/blob/99b7fb1b87d1491578f1fa9c222836341f533d75/colly.go#L551-L559

https://github.com/gocolly/colly/blob/99b7fb1b87d1491578f1fa9c222836341f533d75/colly.go#L1461-L1469

Unfortunately, the current implementaion accepts map[string][]byte, which enforces name to be unique.

Suggestion

Maybe we can accept []Subpart so that:

  1. The order of subparts is guaranteed
  2. filename and other metadata can be optionally included
  3. Duplicate name fields are allowed

and so on.

I would love to hear your opinion! If you think this is feasible, I will start working on it.