Skip to content

Feature Request: Support Square Bracket Notation in Multipart Form Data #3224

@coderabbitai

Description

@coderabbitai

Description

Currently, Fiber supports square bracket notation in form data when using 'application/x-www-form-urlencoded' content type, but this feature is not available for multipart form data. This limits the ability to handle complex nested data structures in multipart form requests.

Current Behavior

  • Square bracket notation works with 'application/x-www-form-urlencoded'
  • Multipart form data does not support square bracket notation for nested structures
  • No support for comma-separated values in multipart form data

Desired Behavior

  • Support square bracket notation in multipart form data (e.g., field[0][name], field[1][name])
  • Support comma-separated values in multipart form data fields
  • Maintain the ability to transfer binary data alongside structured form data

Use Case Example

text_prompts[0][text]: "A beautiful sunset over the ocean"
text_prompts[0][weight]: 0.7
text_prompts[1][text]: "mountain range covered in snow"
text_prompts[1][weight]: -0.5
init_image: <binary_data>

References

  • Original Issue: 🤗 [Question]: bodyParser nested with bracket notation #3223
  • Current Implementation (form-urlencoded):

    fiber/ctx.go

    Lines 394 to 408 in 8c84b0f

    if strings.HasPrefix(ctype, MIMEApplicationForm) {
    data := make(map[string][]string)
    var err error
    c.fasthttp.PostArgs().VisitAll(func(key, val []byte) {
    if err != nil {
    return
    }
    k := c.app.getString(key)
    v := c.app.getString(val)
    if strings.Contains(k, "[") {
    k, err = parseParamSquareBrackets(k)
    }
  • Current Implementation (multipart):

    fiber/ctx.go

    Lines 422 to 427 in 8c84b0f

    if strings.HasPrefix(ctype, MIMEMultipartForm) {
    data, err := c.fasthttp.MultipartForm()
    if err != nil {
    return err
    }
    return c.parseToStruct(bodyTag, out, data.Value)

Additional Notes

This enhancement would provide consistency between form-urlencoded and multipart form data handling, making it easier for developers to work with complex data structures while maintaining the ability to upload files.

Metadata

Metadata

Assignees

Type

No type

Projects

Status

Done

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions