gin file post

fileData, header, err := c.Request.FormFile(fi.Code)
if err == nil && fileData != nil {
    fileName := header.Filename
    formData, formDataContentType, err := getFormData(fileData, fileName)
    if err != nil {
        return nil, err
    }
    fileKey, err := client.AddFile(formData.Bytes(), formDataContentType)
    if err != nil {
        return nil, err
    }
    fs = append(fs, &kintone.File{FileKey: fileKey})
}

func (c *Client) AddFile(body []byte, formDataContentType string) (fileKey string, err error) {
    req, err := http.NewRequest("POST", c.url(APIEndpointFile, ""), bytes.NewBuffer(body))
    if err != nil {
        return
    }
    req.Header.Set("Content-Type", formDataContentType)
    res, err := c.do(nil, req)
    if err != nil {
        return
    }
    body, err = ioutil.ReadAll(res.Body)
    res.Body.Close()
    if err != nil {
        return
    }
    if res.StatusCode != 200 {
        err = fmt.Errorf(string(body))
        return
    }
    var t struct {
        FileKey string `json:"filekey"`
    }
    if err = json.Unmarshal(body, &t); err != nil {
        return
    }
    fileKey = t.FileKey
    return
}

func getFormData(fileData multipart.File, fileName string) (*bytes.Buffer, string, error) {
    formData := &bytes.Buffer{}
    writer := multipart.NewWriter(formData)
    h := make(textproto.MIMEHeader)
    h.Set("Content-Disposition", fmt.Sprintf(`form-data; name="file"; filename="%s"`, fileName))
    h.Set("Content-Type", "text/plain")
    fw, _ := writer.CreatePart(h)
    io.Copy(fw, fileData)
    formDataContentType := writer.FormDataContentType()
    writer.Close()
    return formData, formDataContentType, nil
}