文件判断修改

This commit is contained in:
lifeiyi
2020-03-11 16:35:22 +08:00
parent 4926100b5b
commit be5b1b8999

View File

@@ -408,12 +408,12 @@ func staticServer(routerUrl string, routerData RouterStaticResoutceData, w http.
defer resourceFile.Close() defer resourceFile.Close()
//重新拼接文件名 //重新拼接文件名
imgFormat := strings.Split(resourceFileHeader.Filename, ".") imgFormat := strings.Split(resourceFileHeader.Filename, ".")
if len(imgFormat) != 2 { if len(imgFormat) < 2 {
writeResp(http.StatusNotFound, "not a file") writeResp(http.StatusNotFound, "not a file")
return return
} }
filePrefixName := uuid.Rand().HexEx() filePrefixName := uuid.Rand().HexEx()
fileName := filePrefixName + "." + imgFormat[1] fileName := filePrefixName + "." + imgFormat[len(imgFormat)-1]
//创建文件 //创建文件
localpath := fmt.Sprintf("%s%s", destLocalPath, fileName) localpath := fmt.Sprintf("%s%s", destLocalPath, fileName)
localfd, err := os.OpenFile(localpath, os.O_WRONLY|os.O_CREATE, 0666) localfd, err := os.OpenFile(localpath, os.O_WRONLY|os.O_CREATE, 0666)