Tencent/WeKnora · error

failed to generate OSS presigned URL: %w

Error message

failed to generate OSS presigned URL: %w

What it means

This wraps a failure from the OSS SDK's client.Presign call, which generates a 24-hour presigned GET URL. Presigning can fail due to invalid credentials/region config, malformed GetObjectRequest, or unsupported client configuration. The URL was never produced, so the caller receives no download link.

Source

Thrown at internal/application/service/file/oss.go:362

	if err := utils.SafeObjectKey(objectName); err != nil {
		return "", fmt.Errorf("invalid file path: %w", err)
	}

	// Determine which client to use
	var client *oss.Client
	if bucketName == s.tempBucketName && s.tempClient != nil {
		client = s.tempClient
	} else {
		client = s.client
	}

	// Generate presigned URL (valid for 24 hours)
	result, err := client.Presign(ctx, &oss.GetObjectRequest{
		Bucket: oss.Ptr(bucketName),
		Key:    oss.Ptr(objectName),
	}, oss.PresignExpires(24*time.Hour))
	if err != nil {
		return "", fmt.Errorf("failed to generate OSS presigned URL: %w", err)
	}

	return result.URL, nil
}

View on GitHub (pinned to 988cbb0330)

Solutions

  1. Verify the OSS client's credentials (AK/SK or STS) are set and valid
  2. Check bucket region matches the client's configured region/endpoint
  3. Log the wrapped SDK error to identify the exact presign failure
  4. Shorten/recheck the 24h expiry if policy limits max presign duration

Example fix

// before
result, err := client.Presign(ctx, req, oss.PresignExpires(24*time.Hour))
if err != nil { return "", fmt.Errorf("failed to generate OSS presigned URL: %w", err) }
// after
result, err := client.Presign(ctx, req, oss.PresignExpires(24*time.Hour))
if err != nil {
    return "", fmt.Errorf("failed to generate OSS presigned URL: %w", err) // inspect %w for credential/region cause
}
Defensive patterns

Strategy: try-catch

Validate before calling

if bucket == "" || objectKey == "" { return errors.New("bucket and key required before presign") }

Try / catch

url, err := svc.GetFileURL(ctx, path)
if err != nil {
    var e *os.PathError
    if errors.Is(err, context.DeadlineExceeded) { /* retry with backoff */ }
    return fmt.Errorf("presign failed: %w", err)
}

Prevention

When it happens

Trigger: Calling GetFileURL when the OSS client has no valid signing credentials, the region/endpoint is wrong for the bucket, or the GetObjectRequest fields are empty/invalid.

Common situations: Missing or expired access-key configuration for the OSS client, anonymous clients that cannot sign, misconfigured custom endpoint/region, clock skew on the host (can surface as signature errors downstream).

Related errors


AI-assisted analysis of Tencent/WeKnora@988cbb0330 (2026-09-02). Data as JSON: /api/errors/033dd6dc3868bad4. Report an issue: GitHub.