attachment

package
v0.8.1 Latest Latest
Warning

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

Go to latest
Published: Dec 16, 2024 License: MIT Imports: 21 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Types = map[string]*typeInfo{
	"image": {
		TypeName: "图片",
		AllowExt: []string{".gif", ".jpg", ".jpeg", ".bmp", ".png", ".ico"},
		MaxSize:  5 * 1024 * 1024,
	},
	"voice": {
		TypeName: "音频",
		AllowExt: []string{".mp3", ".wma", ".wav", ".amr"},
		MaxSize:  50 * 1024 * 1024,
	},
	"video": {
		TypeName: "视频",
		AllowExt: []string{".rm", ".rmvb", ".wmv", ".avi", ".mpg", ".mpeg", ".mp4"},
		MaxSize:  300 * 1024 * 1024,
	},
	"office": {
		TypeName: "办公文件",
		AllowExt: []string{
			".wps", ".wpt", ".doc", ".dot", ".docx", ".docm", ".dotm",
			".et", ".ett", ".xls", ".xlt", ".xlsx", ".xlsm", ".xltx", ".xltm", ".xlsb",
			".dps", ".dpt", ".ppt", ".pps", ".pot", ".pptx", ".ppsx", ".potx",
			".txt", ".csv", ".prn", ".pdf", ".xml",
		},
		MaxSize: 50 * 1024 * 1024,
	},
	"zip": {
		TypeName: "压缩文件",
		AllowExt: []string{".zip", ".rar"},
		MaxSize:  500 * 1024 * 1024,
	},
}

Types 附件类型

Functions

This section is empty.

Types

type Attachment

type Attachment struct {
	Opt *Options // 附件实例化时的参数选项

	GinContext   *gin.Context               // gin上下文
	BaseConfig   *jcbaseGo.AttachmentStruct // 附件配置信息
	RemoteConfig interface{}                // 远程附件配置

	FileType       string // 附件类型
	FileName       string // 附件名
	FileSize       int64  // 附件大小
	FileAttachment string // 附件相对路径
	FileMD5        string // 附件MD5
	FileExt        string // 文件扩展名
	Width          int    // 图片宽
	Height         int    // 图片高
	// contains filtered or unexported fields
}

Attachment 附件结构体,包含文件头信息、扩展名、保存目录和错误列表

func New

func New(args ...interface{}) *Attachment

New 创建一个新的附件实例 args:

  • GinContext *gin.Context Gin 上下文
  • BaseConfig *jcbaseGo.AttachmentStruct 附件配置
  • RemoteConfig interface{} 远程附件配置

func (*Attachment) Error

func (a *Attachment) Error() error

Error 返回第一个捕获的错误

func (*Attachment) Errors

func (a *Attachment) Errors() []error

Errors 返回所有捕获的错误

func (*Attachment) HasError

func (a *Attachment) HasError() bool

HasError 是否有错误

func (*Attachment) Save

func (a *Attachment) Save() *Attachment

Save 保存文件到指定的附件目录

func (*Attachment) SetBeforeSave

func (a *Attachment) SetBeforeSave(fn func(a *Attachment) bool) *Attachment

SetBeforeSave 设置保存文件前的回调函数 - 回调函数返回 true 则继续保存,回调函数返回 false 则跳过

func (*Attachment) ToMedia

func (a *Attachment) ToMedia(src string, args ...interface{}) string

func (*Attachment) Upload

func (a *Attachment) Upload(opt *Options) *Attachment

Upload 初始化文件上传参数

type Options

type Options struct {
	Group string // 附件组,默认不分组(分组会文件类型目录前多一级分组目录)

	FileData interface{} // 文件数据,支持 base64 字符串、*multipart.FileHeader、[]byte
	FileType string      // 文件类型,默认为 image
	MaxSize  int64       // 最大文件大小
	AllowExt []string    // 允许的文件扩展名
}

Options 附件实例化时的参数选项

Directories

Path Synopsis
Package remote 提供多种远程存储方式的统一接口。
Package remote 提供多种远程存储方式的统一接口。

Jump to

Keyboard shortcuts

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