首页 > 代码库 > go multipart/form-data 文件大小,文件信息,处理后缀

go multipart/form-data 文件大小,文件信息,处理后缀

 

 

	for i := 1; i <= 9; i++ {		name := fmt.Sprintf("image%d", i)		file, header, err := r.FormFile(name)		if err != nil {			logs.DebugPrint(err.Error())			break		}		logs.DebugPrint(header.Filename, header.Header, header.Size)		if header.Size > mewNet.MaxImageSize {			code, msg, debugMsg = j.CodeContentTooLong, j.MsgContentTooLong, fmt.Sprintf("max size:%v b 	upload size:%v b", header.Size, mewNet.MaxImageSize)		}		index := strings.LastIndex(header.Filename, ".")		if index < 0 {			code, msg, debugMsg = j.CodeSaveImageError, j.MsgSaveImageError, "not image type"			return		}		subfix := header.Filename[index:]		switch subfix {		case ".jpg", ".jpeg", ".png", ".ico", ".gif", ".wbmp", ".bmp", ".svg", ".webp":		default:			code, msg, debugMsg = j.CodeSaveImageError, j.MsgSaveImageError, "not image type"			return		}		imgType = append(imgType, subfix)		fileNames = append(fileNames, name)		files = append(files, file)	}

下面是 logs.DebugPrint(header.Filename, header.Header, header.Size) 的输出,包含了文件名,文件的http Header,文件大小

default1.jpg map[Content-Disposition:[form-data; name="image1"; filename="default1.jpg"] Content-Type:[application/octet-stream]] 45814

go multipart/form-data 文件大小,文件信息,处理后缀