Skip to content

Instantly share code, notes, and snippets.

@sorashido
Created June 11, 2018 06:48
Show Gist options
  • Save sorashido/6a535cb8f2e19ba621bfdc9f28c33814 to your computer and use it in GitHub Desktop.
Save sorashido/6a535cb8f2e19ba621bfdc9f28c33814 to your computer and use it in GitHub Desktop.
very simple image server
package main
import (
"net/http"
"fmt"
"github.com/gin-gonic/gin"
"github.com/olahol/go-imageupload"
"time"
)
func main() {
r := gin.Default()
r.StaticFS("/get_image", http.Dir("./image/"))
r.POST("/upload", func(c *gin.Context) {
img, err := imageupload.Process(c.Request, "file")
if err != nil {
panic(err)
}
thumb, err := imageupload.ThumbnailPNG(img, 300, 300)
if err != nil {
panic(err)
}
thumb.Save(fmt.Sprintf("./image/%d.png", time.Now().Unix()))
c.Redirect(http.StatusMovedPermanently, "/")
})
r.Run(":5000")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment