修复文件上传超过1GB报错的bug

This commit is contained in:
gsw945 2023-03-20 14:30:27 +08:00
parent 5f3b2fa1ef
commit 4cdafc80b4
4 changed files with 45 additions and 34 deletions

View File

@ -343,6 +343,10 @@ func ResolveCommand(args []string) {
web.BConfig.WebConfig.StaticDir["/uploads"] = uploads
web.BConfig.WebConfig.ViewsPath = conf.WorkingDir("views")
web.BConfig.WebConfig.Session.SessionCookieSameSite = http.SameSiteDefaultMode
var upload_file_size = conf.GetUploadFileSize()
if upload_file_size > web.BConfig.MaxUploadSize {
web.BConfig.MaxUploadSize = upload_file_size
}
fonts := conf.WorkingDir("static", "fonts")

View File

@ -77,7 +77,9 @@ token_size=12
#上传文件的后缀,如果不限制后缀可以设置为 *
upload_file_ext=txt|doc|docx|xls|xlsx|ppt|pptx|pdf|7z|rar|jpg|jpeg|png|gif
#上传的文件大小限制,如果不填写,默认不限制,单位可以是 GB KB MB
#上传的文件大小限制
# - 如果不填写, 则默认1GB如果希望超过1GB必须带单位
# - 如果填写,单位可以是 TB、GB、MB、KB不带单位表示字节
upload_file_size=10MB
####################邮件配置######################

View File

@ -128,9 +128,9 @@ func GetUploadFileExt() []string {
func GetUploadFileSize() int64 {
size := web.AppConfig.DefaultString("upload_file_size", "0")
if strings.HasSuffix(size, "MB") {
if strings.HasSuffix(size, "TB") {
if s, e := strconv.ParseInt(size[0:len(size)-2], 10, 64); e == nil {
return s * 1024 * 1024
return s * 1024 * 1024 * 1024 * 1024
}
}
if strings.HasSuffix(size, "GB") {
@ -138,13 +138,18 @@ func GetUploadFileSize() int64 {
return s * 1024 * 1024 * 1024
}
}
if strings.HasSuffix(size, "MB") {
if s, e := strconv.ParseInt(size[0:len(size)-2], 10, 64); e == nil {
return s * 1024 * 1024
}
}
if strings.HasSuffix(size, "KB") {
if s, e := strconv.ParseInt(size[0:len(size)-2], 10, 64); e == nil {
return s * 1024
}
}
if s, e := strconv.ParseInt(size, 10, 64); e == nil {
return s * 1024
return s
}
return 0
}