Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/krilie/go-sfile
s-file gin upload file to local path and delete file
https://github.com/krilie/go-sfile
file gin go golang upload-file
Last synced: 4 days ago
JSON representation
s-file gin upload file to local path and delete file
- Host: GitHub
- URL: https://github.com/krilie/go-sfile
- Owner: krilie
- Created: 2019-09-05T10:24:49.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2020-08-11T03:17:35.000Z (over 4 years ago)
- Last Synced: 2024-11-08T12:56:43.552Z (7 days ago)
- Topics: file, gin, go, golang, upload-file
- Language: Go
- Homepage:
- Size: 7.81 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# s-file
s-file gin upload file to local path and delete file## use
go get github.com/krilie/s-file## example
```golang
func main() {
sfile := s_file.NewSFile("./files")
gin.SetMode(gin.DebugMode)
engine := gin.New()
engine.POST("/upload", func(c *gin.Context) {
fileHeader, err := c.FormFile("file")
if err != nil {
c.JSON(400, gin.H{"msg": err.Error()})
return
}
log.Printf("upload file %v", fileHeader.Filename)
file, err := fileHeader.Open()
if err != nil {
c.JSON(400, gin.H{"msg": err.Error()})
return
}
defer file.Close()
content, key, err := sfile.SaveFile(c, fileHeader.Filename, file)
if err != nil {
c.JSON(400, gin.H{"msg": err.Error()})
return
}
c.JSON(200, gin.H{"msg": content, "key": key, "size": fileHeader.Size})
return
})
engine.POST("/delete/:key", func(c *gin.Context) {
err := sfile.DeleteFile(c, c.Param("key"))
if err != nil {
c.JSON(400, gin.H{"msg": err.Error()})
return
}
c.JSON(200, gin.H{"msg": "ok"})
return
})
err := engine.Run(":80")
log.Println(err)
}
```