Skip to content

Instantly share code, notes, and snippets.

@prongbang
Created February 17, 2021 02:59
Show Gist options
  • Save prongbang/d08f460d8edfad99b058118ea3c58443 to your computer and use it in GitHub Desktop.
Save prongbang/d08f460d8edfad99b058118ea3c58443 to your computer and use it in GitHub Desktop.

Golang

func Upload(c *fiber.Ctx) error {
  if form, err := c.MultipartForm(); err == nil {
    files := form.File["image"]
    for _, file := range files {
      fmt.Println(file.Filename, file.Size, file.Header["Content-Type"][0])
      _ = c.SaveFile(file, fmt.Sprintf("./%s", file.Filename))
    }
  }
}

Axios client

let formData = new FormData();
for (let f of body.data) {
  formData.append('image', f);
}
let {status} = await this.$axios.post(`/image`, formData);
return status === 201 || status === 200
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment