增加图片上传对png和gif格式的支持

master
a7458969 2019-12-28 15:37:49 +08:00
parent dab24f3f84
commit b77bb98f3f
4 changed files with 28 additions and 0 deletions

1
.gitignore vendored
View File

@ -9,3 +9,4 @@ pem/client-cert.pem
pem/ca.pem
id_rsa
background
image/

View File

@ -51,7 +51,11 @@ func GetArticles(c *gin.Context) {
logs.Error(e.Error())
return
}
for k,_ := range article{
article[k].Content += "..."
}
rsp.Data = article
rsp.Status = 0
rsp.Msg = "OK"
}

View File

@ -46,6 +46,28 @@ func (this *FileController) OnUpload(c *gin.Context) {
log.Print(len(bytes))
c.JSON(200, map[string] interface{}{"url":uid.String()})
}
if strings.Contains(types,"png"){
defer file.Close()
out, err := os.Create("image/" + uid.String() + ".png")
if err != nil {
log.Fatal(err)
}
defer out.Close()
out.Write(bytes)
log.Print(len(bytes))
c.JSON(200, map[string] interface{}{"url":uid.String()})
}
if strings.Contains(types,"gif"){
defer file.Close()
out, err := os.Create("image/" + uid.String() + ".gif")
if err != nil {
log.Fatal(err)
}
defer out.Close()
out.Write(bytes)
log.Print(len(bytes))
c.JSON(200, map[string] interface{}{"url":uid.String()})
}
}
func (this *FileController) OnDownLoad(c *gin.Context) {

View File

@ -3,6 +3,7 @@ SET GOOS=linux
SET GOARCH=amd64
go build ./
ssh -t -i ./id_rsa ubuntu@118.24.238.198 'pkill userapi'
ssh -t -i ./id_rsa ubuntu@118.24.238.198 'rm /home/ubuntu/api/bin/userapi'