feat(upload): detect and specify mime type for files uploaded to S3 and OSS (fix#1681)

This commit is contained in:
Aaron Liu
2023-05-25 19:51:51 +08:00
parent 4aafe1dc7a
commit 89ee147961
5 changed files with 22 additions and 9 deletions

View File

@@ -2,6 +2,7 @@ package fsctx
import (
"errors"
"github.com/HFO4/aliyun-oss-go-sdk/oss"
"io"
"time"
)
@@ -17,7 +18,7 @@ const (
type UploadTaskInfo struct {
Size uint64
MIMEType string
MimeType string
FileName string
VirtualPath string
Mode WriteMode
@@ -30,6 +31,15 @@ type UploadTaskInfo struct {
Src string
}
// Get mimetype of uploaded file, if it's not defined, detect it from file name
func (u *UploadTaskInfo) DetectMimeType() string {
if u.MimeType != "" {
return u.MimeType
}
return oss.TypeByExtension(u.FileName)
}
// FileHeader 上传来的文件数据处理器
type FileHeader interface {
io.Reader
@@ -51,7 +61,7 @@ type FileStream struct {
Size uint64
VirtualPath string
Name string
MIMEType string
MimeType string
SavePath string
UploadSessionID *string
AppendStart uint64
@@ -90,7 +100,7 @@ func (file *FileStream) Seekable() bool {
func (file *FileStream) Info() *UploadTaskInfo {
return &UploadTaskInfo{
Size: file.Size,
MIMEType: file.MIMEType,
MimeType: file.MimeType,
FileName: file.Name,
VirtualPath: file.VirtualPath,
Mode: file.Mode,