Add upload file example
This commit is contained in:
		
							
								
								
									
										26
									
								
								README.md
									
									
									
									
									
								
							
							
						
						
									
										26
									
								
								README.md
									
									
									
									
									
								
							@ -218,6 +218,32 @@ func main() {
 | 
				
			|||||||
id: 1234; page: 1; name: manu; message: this_is_great
 | 
					id: 1234; page: 1; name: manu; message: this_is_great
 | 
				
			||||||
```
 | 
					```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					### Another example: upload file
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					Reference issue [#548](https://github.com/gin-gonic/gin/issues/548)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					```go
 | 
				
			||||||
 | 
					func main() {
 | 
				
			||||||
 | 
						router := gin.Default()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						router.POST("/upload", func(c *gin.Context) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						        file, header , err := c.Request.FormFile("upload")
 | 
				
			||||||
 | 
						        filename := header.Filename
 | 
				
			||||||
 | 
						        fmt.Println(header.Filename)
 | 
				
			||||||
 | 
						        out, err := os.Create("./tmp/"+filename+".png")
 | 
				
			||||||
 | 
						        if err != nil {
 | 
				
			||||||
 | 
						            log.Fatal(err)
 | 
				
			||||||
 | 
						        }
 | 
				
			||||||
 | 
						        defer out.Close()
 | 
				
			||||||
 | 
						        _, err = io.Copy(out, file)
 | 
				
			||||||
 | 
						        if err != nil {
 | 
				
			||||||
 | 
						            log.Fatal(err)
 | 
				
			||||||
 | 
						        }   
 | 
				
			||||||
 | 
						})
 | 
				
			||||||
 | 
						router.Run(":8080")
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#### Grouping routes
 | 
					#### Grouping routes
 | 
				
			||||||
```go
 | 
					```go
 | 
				
			||||||
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user