Documentation ¶
Index ¶
- Constants
- func CopyFile(src, dst string) error
- func CreateSavePath(dst string, perm os.FileMode) error
- func DIR() string
- func Exist(path string) (bool, error)
- func FILE() string
- func GetFileContent(filePath string) ([]byte, error)
- func GetFileContentString(filePath string) (string, error)
- func GetFileHeaderMd5Name(fileHeader *multipart.FileHeader) (string, error)
- func GetFileList(path string) []string
- func LINE() int
- func MergeChunk(url string, fileMergeReq *FileMergeReq) (*gohttp.Response, error)
- func RemoveFile(file string) error
- func SaveFile(file *multipart.FileHeader, dst string) error
- func SaveToLocal(savePath string, chunk *FileChunk) error
- func Trace(skip int) (arr []string)
- func UploadChunk(url string, chunk *FileChunk) (*gohttp.Response, error)
- func WriteToFile(filename string, b []byte) error
- type BigFile
- type FileChunk
- type FileMergeReq
- type FileReceiveResult
- func MergeFileForChunks(filePath string, fileName string, fileMd5 string, totalChunks int64, ...) (*FileReceiveResult, error)
- func ReceiveChunkHandler(assetsDir string, chunkIndex int64, chunkMd5 string, fileMd5 string, ...) (*FileReceiveResult, error)
- func ReceiveFile(assetsDir string, file *multipart.FileHeader) (*FileReceiveResult, error)
Constants ¶
View Source
const ( UPLOAD_TYPE_LOCAL = 1 UPLOAD_TYPE_OSS = 2 UPLOAD_TYPE_CHUNK = 3 )
View Source
const (
EL = "\n"
)
Variables ¶
This section is empty.
Functions ¶
func GetFileContent ¶ added in v1.2.42
func GetFileContentString ¶ added in v1.2.42
func GetFileHeaderMd5Name ¶
func GetFileHeaderMd5Name(fileHeader *multipart.FileHeader) (string, error)
func MergeChunk ¶ added in v1.2.37
func MergeChunk(url string, fileMergeReq *FileMergeReq) (*gohttp.Response, error)
分片全部上传完毕后,再请求文件分片合并请求(作为客户端请求时验证非法请求认证逻辑需要加,如authToken sign 等等)
func RemoveFile ¶
func SaveToLocal ¶ added in v1.2.37
//////////////////////////////////////////////////////////////local save 把分片存在指定目录
func UploadChunk ¶ added in v1.2.34
////////////////////////////////////////////////////////////// http server upload and merge 供参考 上传一个文件分片,(作为客户端请求时验证非法请求认证逻辑需要加,如authToken sign 等等)
Types ¶
type BigFile ¶ added in v1.2.34
type BigFile struct { ChunkSize int64 // 分片大小 M MaxWorkers int // 同时处理最大分块数量,合理用防止超大文件内存益处 File string // 文件路径 FileMd5 string // 文件Md5 ChunkCount int64 // 分片数量 FileChunkCallback func(chunk *FileChunk) error // 分片处理消息 SuccessChunkIndexes []int64 //处理成功的碎片index ErrorGroup goutils.ErrorGroup // contains filtered or unexported fields }
type FileChunk ¶ added in v1.2.34
type FileChunk struct { Data []byte //分片数据 Hash string //分片Hash Index int64 //分片顺序号 OriginalFileName string //原文件名 OriginalFileMd5 string //原文件Md5 FileName string //分片文件名称 }
fmt.Sprintf("%s.part%d", fileName, i) mapreduce big file 大文件逻辑 for 把大文件并发分片处理,为了防止OOM超大文件边分片边处理的策略
type FileMergeReq ¶ added in v1.2.37
type FileReceiveResult ¶ added in v1.2.37
func MergeFileForChunks ¶ added in v1.2.37
func MergeFileForChunks(filePath string, fileName string, fileMd5 string, totalChunks int64, isNotRemoveChunk bool) (*FileReceiveResult, error)
服务器合并所有文件分片,并验证md5, isNotRemoveChunk =true 合并后时不会删除分片
func ReceiveChunkHandler ¶ added in v1.2.34
func ReceiveChunkHandler(assetsDir string, chunkIndex int64, chunkMd5 string, fileMd5 string, file *multipart.FileHeader) (*FileReceiveResult, error)
服务器接受文件分片
func ReceiveFile ¶ added in v1.2.34
func ReceiveFile(assetsDir string, file *multipart.FileHeader) (*FileReceiveResult, error)
服务器接受file文件到assetsDir目录下,assetsDir 目录不存在则自动创建,返回存储位置
Click to show internal directories.
Click to hide internal directories.