//控制器处理方法:AttachController:
type AttachController struct {
beego.Controller
}
func (this *AttachController)Get(){
filePath,err:=url.QueryUnescape(this.Ctx.Request.RequestURI[1:])
beego.Info(this.Ctx.Request.RequestURI[1:])
if err!=nil{
this.Ctx.WriteString(err.Error())
return
}
f,err:=os.Open(filePath)
if err!=nil{
this.Ctx.WriteString(err.Error())
return
}
defer f.Close()
_,err=io.Copy(this.Ctx.ResponseWriter,f)
if err!=nil{
this.Ctx.WriteString(err.Error())
return
}
}
router:
//作为控制器处理文件
beego.Router("/attachment/:all",&controllers.AttachController{})
//作为静态文件处理方法
//作为静态文件
//beego.SetStaticPath("/attachment","attachment")