File tree Expand file tree Collapse file tree 1 file changed +26
-0
lines changed Expand file tree Collapse file tree 1 file changed +26
-0
lines changed Original file line number Diff line number Diff line change @@ -218,6 +218,32 @@ func main() {
218
218
id: 1234; page: 1; name: manu; message: this_is_great
219
219
` ` `
220
220
221
+ # ## Another example: upload file
222
+
223
+ Reference issue [# 548](https://github.com/gin-gonic/gin/issues/548)
224
+
225
+ ` ` ` go
226
+ func main () {
227
+ router := gin.Default ()
228
+
229
+ router.POST(" /upload" , func(c * gin.Context) {
230
+
231
+ file, header , err := c.Request.FormFile(" upload" )
232
+ filename := header.Filename
233
+ fmt.Println(header.Filename)
234
+ out, err := os.Create(" ./tmp/" +filename+" .png" )
235
+ if err ! = nil {
236
+ log.Fatal(err)
237
+ }
238
+ defer out.Close ()
239
+ _, err = io.Copy(out, file)
240
+ if err ! = nil {
241
+ log.Fatal(err)
242
+ }
243
+ })
244
+ router.Run(" :8080" )
245
+ }
246
+ ` ` `
221
247
222
248
# ### Grouping routes
223
249
` ` ` go
You can’t perform that action at this time.
0 commit comments