使用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.
请问谁知道这是什么原因么?谢谢了!