fix(storage): auto-detect content-type to resolve image rendering issues

Fixes #995. Added mime type detection in SaveBytes for MinIO, OSS, S3, and TOS to prevent images from being incorrectly saved as text/csv.
This commit is contained in:
jw_mac
2026-04-20 19:14:55 +08:00
committed by lyingbug
parent ede7dd08a2
commit 09e1642335
5 changed files with 64 additions and 59 deletions
+2 -2
View File
@@ -172,7 +172,7 @@ func (s *ossFileService) SaveFile(ctx context.Context,
contentType := file.Header.Get("Content-Type")
if contentType == "" {
contentType = getContentTypeByExt(ext)
contentType = utils.GetContentTypeByExt(ext)
}
// Use Uploader for files > 10MB (auto multipart with concurrent uploads)
@@ -233,7 +233,7 @@ func (s *ossFileService) SaveBytes(ctx context.Context, data []byte, tenantID ui
Bucket: oss.Ptr(targetBucket),
Key: oss.Ptr(objectName),
Body: bytes.NewReader(data),
ContentType: oss.Ptr("text/csv; charset=utf-8"),
ContentType: oss.Ptr(utils.GetContentTypeByExt(ext)),
})
if err != nil {
return "", fmt.Errorf("failed to upload bytes to OSS: %w", err)