Files
Mycontent/soul-api/internal/handler/oss.go
乘风 2645212d47 feat: update API base URLs and enhance icon designs
- Updated the API base URLs in app.js to point to local development server for testing.
- Enhanced SVG icons with gradient fills for improved visual appeal across various components.
- Refactored the avatar upload functionality in avatar-nickname.js and profile-edit.js to utilize a new upload utility for better code maintainability.
- Improved the layout and styling of the my page and super article editor for a more user-friendly interface.

This update aims to streamline development processes and enhance the overall user experience in the application.
2026-05-09 16:00:16 +08:00

34 lines
980 B
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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...)
}