From 2d78c86879238a566e182161e0751420856200af Mon Sep 17 00:00:00 2001 From: a74589669 <290198252@qq.com> Date: Tue, 3 Sep 2019 16:38:35 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=87=E7=AB=A0=E6=8E=A5=E5=8F=A3=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0markdown=E5=9B=BE=E5=83=8F=E4=B8=8A=E4=BC=A0=E6=B5=8B?= =?UTF-8?q?=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- controller/file.go | 17 +++++++++++------ deploy.bat | 3 +++ main.go | 10 +++++++--- 3 files changed, 21 insertions(+), 9 deletions(-) diff --git a/controller/file.go b/controller/file.go index 82766eb..bc5c040 100644 --- a/controller/file.go +++ b/controller/file.go @@ -37,7 +37,7 @@ func (this *FileController) OnUpload(c *gin.Context) { // jpg if strings.Contains(types,"jpeg"){ defer file.Close() - out, err := os.Create("G://image//" + uid.String() + ".jpg") + out, err := os.Create("image/" + uid.String() + ".jpg") if err != nil { log.Fatal(err) } @@ -50,25 +50,30 @@ func (this *FileController) OnUpload(c *gin.Context) { func (this *FileController) OnDownLoad(c *gin.Context) { resp := RespBase{Msg:"FAIL",Status: 211} - defer func() { - c.JSON(200,resp) - }() + fileName := c.Param("file") if "" == fileName{ + c.JSON(200,resp) + return } - file,e := os.Open("G://image//" +fileName) + file,e := os.Open("/home/ubuntu/api/bin/image/" +fileName + ".jpg") if nil != e{ log.Print(e.Error()) + c.JSON(200,resp) + return } bytes,e :=ioutil.ReadAll(file) if nil != e{ log.Print(e.Error()) + c.JSON(200,resp) + return } + c.Header("X-Content-Type-Options", "nosniff") c.Header("Content-Type","image/png") c.Header("Content-Disposition", - "G://image//" +fileName) + "/image/" +fileName) c.Writer.Write(bytes) } diff --git a/deploy.bat b/deploy.bat index b48eceb..a74f768 100644 --- a/deploy.bat +++ b/deploy.bat @@ -3,6 +3,9 @@ SET GOOS=linux SET GOARCH=amd64 go build ./ + +ssh -t -i ./id_rsa ubuntu@118.24.238.198 'rm /home/ubuntu/api/bin/userapi' + scp -i ./id_rsa background ubuntu@118.24.238.198:/home/ubuntu/api/bin/userapi scp -i ./id_rsa user.yaml ubuntu@118.24.238.198:/home/ubuntu/api/bin/user.yaml diff --git a/main.go b/main.go index f7e5e38..71f1c52 100644 --- a/main.go +++ b/main.go @@ -43,11 +43,15 @@ func InitLogs() { logs.Init(config.GetLogConfig().Dir, config.GetLogConfig().File, config.GetLogConfig().Level, config.GetLogConfig().SaveFile) } func CORSMiddleware(c *gin.Context) { - ori := c.Request.Header.Get("Origin") c.Writer.Header().Set("Access-Control-Allow-Methods", "POST, GET, OPTIONS, PUT, DELETE, UPDATE") - c.Writer.Header().Set("Access-Control-Allow-Origin", ori) + c.Writer.Header().Set("Access-Control-Allow-Origin", "http://172.21.102.193:8080") c.Writer.Header().Set("Access-Control-Max-Age", "86400") - c.Writer.Header().Set("Access-Control-Allow-Headers", "X-Requested-With, Content-Type, Origin, Authorization, Accept, Client-Security-Token, Accept-Encoding, x-access-token") + c.Writer.Header().Set("Access-Control-Allow-Headers", + "X-Requested-With," + + " Content-Type, Origin, Authorization," + + "Accept,Client-Security-Token, Accept-Encoding," + + "x-access-token,Access-Control-Request-Method," + + "Access-Control-Request-Headers") c.Writer.Header().Set("Access-Control-Expose-Headers", "Content-Length") c.Writer.Header().Set("Access-Control-Allow-Credentials", "true")