Search code examples
gogo-gin

Gin, Get form-data nested object sending with postman


So basically I want to use PostFormMap() method to get my data sent from postman's form-data but I get unexpected result and the reason that I'm not using raw json is that I want to upload a file too Here is my postman

enter image description here

here is the code (nothing fancy)

c.JSON(200, gin.H{
    "request": c.PostFormMap("rules"),
})

and I'm expecting to get

{
    "request": [
        {
            "cell": "A",
            "rule": "B"
        },
        {
            "cell": "B",
            "rule": "D"
        }
    ]
}

but instead I get this

{
    "request": {
        "0": "B",
        "1": "D"
    }
}

The question is how can I get the correct result?


Solution

  • Answering my own question

    After spending hours of searching and having PHP background in my mind I realized that having such form-data parameter like foo[0][bar] manually implemented in PHP and is not a standard thing so in my case I decided to send the second parameter as a raw json so it would be

    Postman Body => form-data

    Key Value
    file sample.xlsx
    rules [{"cell": "A", "rules": "string"}, {"cell": "B", "rules": "numeric"}]