beego文件上传服务器,beego上传文件的关闭问题

使用beego做一个上传功能,使用如下代码:

// 获取上传文件

f, h, err := this.GetFile("editormd-image-file")

if err == nil {

// 关闭文件

f.Close()

}

if err != nil {

// 获取错误则输出错误信息

this.Data["json"] = map[string]interface{}{"success": 0, "message": err.Error()}

this.ServeJson()

return

}

// 获取当前年月

datePath := time.Now().Format("2006/01")

// 设置保存目录

dirPath := "./upload/" + datePath

// 设置保存文件名

FileName := h.Filename

// 将文件保存到服务器中

err = this.SaveToFile("editormd-image-file", fmt.Sprintf("%s/%s", dirPath, FileName))

if err != nil {

// 出错则输出错误信息

this.Data["json"] = map[string]interface{}{"success": 0, "message": err.Error()}

this.ServeJson()

return

}

前端使用的editor.md,上传一切正常,但是却发现,如果我一直连续上传,传个三四福图左右,那么就会出现一个情况,在上传目录下会出现tmp这个临时文件夹,而且不会自动删除,也就是表明我的文件并没有被正确关闭,可是我已经在程序里关闭了啊!

而且,出现这样的情况时候,会发现,现在只要刷新,那么之前注册的静态文件也会失效,服务端直接报错:

2015/07/01 01:24:28 [staticfile.go:61] [W] GetFileAttributesEx static/css/admin.

css: The system cannot find the path specified.

2015/07/01 01:24:28 [staticfile.go:61] [W] GetFileAttributesEx static/img/logo.p

ng: The system cannot find the path specified.

2015/07/01 01:24:28 [staticfile.go:61] [W] GetFileAttributesEx static/js/editor/

css/editormd.min.css: The system cannot find the path specified.

2015/07/01 01:24:28 [staticfile.go:61] [W] GetFileAttributesEx static/js/validat

ion/bootstrapValidator.js: The system cannot find the path specified.

2015/07/01 01:24:28 [staticfile.go:61] [W] GetFileAttributesEx static/js/editor/

editormd.min.js: The system cannot find the path specified.

2015/07/01 01:24:28 [staticfile.go:61] [W] GetFileAttributesEx static/js/tagsinp

ut/bootstrap-tagsinput.js: The system cannot find the path specified.

2015/07/01 01:24:28 [staticfile.go:61] [W] GetFileAttributesEx static/js/admin.j

s: The system cannot find the path specified.

请问谁知道这是什么原因么?谢谢了!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值