title: How to get file posted from JSON in go gin?
body: <p>I want to save image file posted by JSON. </p>
  
  <p>Here is the struct of the post:</p>
  
  <pre><code>type Article struct {
      Title   string `json:"title"`
      Body string `json:"body"`
      File    []byte `json:"file"`
  }
  </code></pre>
  
  <p>And the handler is :</p>
  
  <pre><code>   func PostHandler(c *gin.Context) {
          var err error
          var json Article
          err = c.BindJSON(&amp;json)
          if err != nil {
              log.Panic(err)
          }
  
      //handle photo upload
          var filename string
          file, header, err := json.File  //assignment count mismatch: 3 = 1
  
          if err != nil {
              fmt.Println(err)
              filename = ""
  
          } else {
              data, err := ioutil.ReadAll(file)
              if err != nil {
                  fmt.Println(err)
                  return
              }
  
              filename = path.Join("media", +shared.RandString(5)+path.Ext(header.Filename))
  
              err = ioutil.WriteFile(filename, data, 0777)
              if err != nil {
                  io.WriteString(w, err.Error())
                  return
              }
  
          }
  ...
  </code></pre>
  
  <p>But I get </p>
  
  <blockquote>
    <p>assignment count mismatch: 3 = 1</p>
  </blockquote>
  
  <p>I copied the file handling part from a working multipart form handler which worked fine but apparently, </p>
  
  <pre><code>file, header, err := r.FormFile("uploadfile")
  </code></pre>
  
  <p>can not be translated into JSON handling. </p>
  
  <p>I have looked at gin docs but could not find examples involving json file handling. 
  So how can I fix this?</p>