package handler import ( "bytes" "fmt" "io" "mime/multipart" "path/filepath" alioss "github.com/aliyun/aliyun-oss-go-sdk/oss" soulOss "soul-api/internal/oss" ) // ossUploadFile / ossUploadBytes 统一走 internal/oss.Upload(与 POST …/upload 同源:system_config.oss_config + ObjectPublicURL)。 func ossUploadFile(file multipart.File, folder, filename string) (string, error) { data, err := io.ReadAll(file) if err != nil { return "", fmt.Errorf("读取文件失败: %w", err) } objectKey := filepath.ToSlash(filepath.Join("uploads", folder, filename)) return soulOss.Upload(objectKey, bytes.NewReader(data)) } func ossUploadBytes(data []byte, folder, filename, contentType string) (string, error) { objectKey := filepath.ToSlash(filepath.Join("uploads", folder, filename)) var opts []alioss.Option if contentType != "" { opts = append(opts, alioss.ContentType(contentType)) } return soulOss.Upload(objectKey, bytes.NewReader(data), opts...) }