upload

package
v1.59.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 17, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package upload 提供 multipart 文件上传封装: 大小/扩展名校验 + 存储联动(对象存储或本地目录)+ 统一文件信息返回。 场景:直播封面、头像、附件上传。

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	// MaxSize 单文件大小上限(字节),0 表示不限制。
	MaxSize int64
	// AllowedExt 允许的扩展名(小写,如 ".jpg" ".png");空表示不限制。
	AllowedExt []string
}

Config 上传配置。

type FileInfo

type FileInfo struct {
	// Name 原始文件名。
	Name string
	// Ext 扩展名(小写,含点)。
	Ext string
	// Size 文件大小(字节)。
	Size int64
	// Content 文件内容(小文件场景直接使用;大文件建议先落盘)。
	Content []byte
	// Header 原始 multipart 头。
	Header *multipart.FileHeader
}

FileInfo 上传文件信息。

func Parse

func Parse(ctx iris.Context, formField string, config Config) (*FileInfo, error)

Parse 解析并校验 multipart 文件(formField 为表单字段名)。 校验失败返回错误(大小超限/扩展名不允许/字段缺失)。

func ParseRequest

func ParseRequest(r *http.Request, formField string, config Config) (*FileInfo, error)

ParseRequest 从标准 net/http 请求解析 multipart 文件。

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL