文章接口添加markdown图像上传测试

master
a74589669 2019-09-03 16:38:35 +08:00
parent 3509535dae
commit 2d78c86879
3 changed files with 21 additions and 9 deletions

View File

@ -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)
}

View File

@ -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

10
main.go
View File

@ -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")