Tencent/WeKnora · error

invalid file name: %w

Error message

invalid file name: %w

What it means

MinIO SaveBytes guard: the supplied file name was rejected by SafeFileName, meaning it contains unsafe characters or traversal-like constructs, so a sanitized export object key cannot be derived and the byte upload is refused.

Source

Thrown at internal/application/service/file/minio.go:207

	_, err = s.client.CopyObject(ctx,
		minio.CopyDestOptions{Bucket: s.bucketName, Object: destKey},
		minio.CopySrcOptions{Bucket: s.bucketName, Object: srcKey},
	)
	if err != nil {
		return "", fmt.Errorf("failed to copy file in MinIO: %w", err)
	}

	newPath := fmt.Sprintf("minio://%s/%s", s.bucketName, destKey)
	logger.Infof(ctx, "Copied MinIO object %s to %s", srcPath, newPath)
	return newPath, nil
}

// SaveBytes saves bytes data to MinIO and returns the file path
// temp parameter is ignored for MinIO (no auto-expiration support in this implementation)
func (s *minioFileService) SaveBytes(ctx context.Context, data []byte, tenantID uint64, fileName string, temp bool) (string, error) {
	safeName, err := utils.SafeFileName(fileName)
	if err != nil {
		return "", fmt.Errorf("invalid file name: %w", err)
	}
	ext := filepath.Ext(safeName)
	objectName := fmt.Sprintf("%d/exports/%s%s", tenantID, uuid.New().String(), ext)

	// Upload bytes to MinIO
	reader := bytes.NewReader(data)
	_, err = s.client.PutObject(ctx, s.bucketName, objectName, reader, int64(len(data)), minio.PutObjectOptions{
		ContentType: utils.GetContentTypeByExt(ext),
	})
	if err != nil {
		return "", fmt.Errorf("failed to upload bytes to MinIO: %w", err)
	}

	return fmt.Sprintf("minio://%s/%s", s.bucketName, objectName), nil
}

// GetFileURL returns a presigned download URL for the file
func (s *minioFileService) GetFileURL(ctx context.Context, filePath string) (string, error) {

View on GitHub (pinned to 988cbb0330)

Solutions

  1. Pass a plain file name without path separators or special characters
  2. Sanitize file names where they originate
  3. Whitelist extensions for export names
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at internal/application/service/file/minio.go:207 when the library encounters an invalid state.

Common situations: See trigger scenarios.


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