title: how to upload multipart file and json in Go with gin gonic?
body: <p>I'm trying to upload a file to my server with additional information attached to it as json.</p>
  <p>I can upload a file alone with gin doing :</p>
  <pre><code>file, err := c.FormFile(&quot;file&quot;)
  if err != nil {
      return error
  }
  </code></pre>
  <p>But i can't figure out how to pass the file AND the json at the same time.</p>
  <pre><code>type FileJson struct {
      Name        string          `json:&quot;name&quot; binding:&quot;required&quot;`
      Description string           `json:&quot;description&quot;`
      fileData    *multipart.FileHeader `form:&quot;file&quot;`
  }
  
  func UploadFile(c *gin.Context) {
      var testmultipart fileJSON
      err := c.Bind(&amp;testmultipart)
      if err != nil {
          return err
      }
      c.JSON(http.StatusOK, gin.H{&quot;status&quot;: http.StatusText(http.StatusOK), &quot;data&quot;: &quot;xx&quot;})
  }
  </code></pre>
  <p>This doesn't work and doesn't unparse the json data into the struct ( either fialing on the required tag or just having empty field inside the struct )</p>
  <p>Does anybody knows how to do that so that i can send a file + json in on request ?</p>
  <p>One solution would be to encode the file to base64 and unparse it as a []byte but that shouldn't be necessary and make the request larger so i want to do it with mime/multipart.</p>