fix(fe): 修社区图片撑破网格;发帖限 3 张;上传偶发失败自动重试 #5
@@ -8,6 +8,7 @@ import (
|
|||||||
"io"
|
"io"
|
||||||
"path"
|
"path"
|
||||||
"strings"
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/sundynix/pets-be/internal/model"
|
"github.com/sundynix/pets-be/internal/model"
|
||||||
)
|
)
|
||||||
@@ -41,7 +42,9 @@ func (s *Service) UploadFile(reader io.Reader, filename, contentType string) (*m
|
|||||||
if contentType == "" {
|
if contentType == "" {
|
||||||
contentType = "application/octet-stream"
|
contentType = "application/octet-stream"
|
||||||
}
|
}
|
||||||
objectName := "files/" + md5hex + ext
|
// 按上传月份分文件夹:uploads/2026-07/<md5>.jpg。文件名仍用 md5 保证唯一。
|
||||||
|
// 同内容命中上面的去重直接复用,不会因为跨月再传一份
|
||||||
|
objectName := "uploads/" + time.Now().Format("2006-01") + "/" + md5hex + ext
|
||||||
url, err := s.storage.Upload(objectName, bytes.NewReader(data), int64(len(data)), contentType)
|
url, err := s.storage.Upload(objectName, bytes.NewReader(data), int64(len(data)), contentType)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|||||||
Reference in New Issue
Block a user