fix: 文件上传名称去除空格
This commit is contained in:
@@ -60,9 +60,12 @@ func uploadWhiteList() []string {
|
||||
// fileName 原始文件名称含后缀,如:logo.png
|
||||
func generateFileName(fileName string) string {
|
||||
fileExt := filepath.Ext(fileName)
|
||||
// 替换掉后缀和特殊字符保留文件名
|
||||
// 去除后缀
|
||||
newFileName := regular.Replace(fileName, fileExt, "")
|
||||
newFileName = regular.Replace(newFileName, `[<>:"\\|?*]+`, "")
|
||||
// 去除非法字符
|
||||
newFileName = regular.Replace(newFileName, `[\\/:*?"<>|]`, "")
|
||||
// 去除空格
|
||||
newFileName = regular.Replace(newFileName, `\s`, "_")
|
||||
newFileName = strings.TrimSpace(newFileName)
|
||||
return fmt.Sprintf("%s_%s%s", newFileName, generate.Code(6), fileExt)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user