Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support upload single or multiple files. #775

Merged
merged 1 commit into from Dec 27, 2016
Merged

Support upload single or multiple files. #775

merged 1 commit into from Dec 27, 2016

Conversation

appleboy
Copy link
Member

@appleboy appleboy commented Dec 24, 2016

Fixed #774

upload single file:

package main

import (
	"github.com/gin-gonic/gin"
	"log"
	"net/http"
)

func main() {
	router := gin.Default()
	router.POST("/upload", func(c *gin.Context) {
		// single file
		file, _ := c.FormFile("file")
		log.Println(file.Filename)

		c.String(http.StatusOK, "Uploaded...")
	})
	router.Run(":8080")
}

curl command:

curl -X POST http://localhost:8080/upload -F "file=@/Users/mtk10671/z.sh" -H "Content-Type: multipart/form-data"

upload multiple file:

package main

import (
	"github.com/gin-gonic/gin"
	"log"
	"net/http"
)

func main() {
	router := gin.Default()
	router.POST("/upload", func(c *gin.Context) {
		// Multipart form
		form, _ := c.MultipartForm()
		files := form.File["upload[]"]

		for _, file := range files {
			log.Println(file.Filename)
		}
		c.String(http.StatusOK, "Uploaded...")
	})
	router.Run(":8080")
}

curl command:

curl -X POST http://localhost:8080/upload -F "upload[]=@/Users/mtk10671/z.sh" -F "upload[]=@/Users/mtk10671/z.sh" -H "Content-Type: multipart/form-data"

cc @selvam347 @tboerger @javierprovecho @andreynering

Signed-off-by: Bo-Yi Wu appleboy.tw@gmail.com

Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
@codecov-io
Copy link

codecov-io commented Dec 24, 2016

Current coverage is 93.25% (diff: 100%)

Merging #775 into develop will increase coverage by 0.18%

@@            develop       #775   diff @@
==========================================
  Files            16         16          
  Lines          1299       1305     +6   
  Methods           0          0          
  Messages          0          0          
  Branches          0          0          
==========================================
+ Hits           1209       1217     +8   
+ Misses           77         76     -1   
+ Partials         13         12     -1   

Powered by Codecov. Last update 4f439b3...5cc3d59

@appleboy appleboy merged commit df2e95c into develop Dec 27, 2016
@appleboy appleboy deleted the upload branch December 27, 2016 11:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants