feat: Modify COS file service initialization parameters and URL processing logic

This commit is contained in:
begoniezhao
2025-09-15 20:49:34 +08:00
parent 0908f9c487
commit c2d52a9374
2 changed files with 5 additions and 5 deletions
+3 -3
View File
@@ -23,8 +23,8 @@ type cosFileService struct {
}
// NewCosFileService creates a new COS file service instance
func NewCosFileService(appId, region, secretId, secretKey, cosPathPrefix string) (interfaces.FileService, error) {
bucketURL := fmt.Sprintf("https://%s.cos.%s.myqcloud.com", appId, region)
func NewCosFileService(bucketName, region, secretId, secretKey, cosPathPrefix string) (interfaces.FileService, error) {
bucketURL := fmt.Sprintf("https://%s.cos.%s.myqcloud.com/", bucketName, region)
u, err := url.Parse(bucketURL)
if err != nil {
return nil, fmt.Errorf("failed to parse bucketURL: %w", err)
@@ -59,7 +59,7 @@ func (s *cosFileService) SaveFile(ctx context.Context,
if err != nil {
return "", fmt.Errorf("failed to upload file to COS: %w", err)
}
return fmt.Sprintf("https://%s/%s", s.bucketURL, objectName), nil
return fmt.Sprintf("%s%s", s.bucketURL, objectName), nil
}
// GetFile retrieves a file from COS storage by its path URL