Tencent/WeKnora · error

failed to open file: %w

Error message

failed to open file: %w

What it means

Opening the uploaded multipart file header failed before the MinIO upload could begin: the underlying file descriptor could not be opened (already consumed, deleted temp file, or I/O error), so nothing is uploaded.

Source

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

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

// SaveFile saves a file to MinIO
func (s *minioFileService) SaveFile(ctx context.Context,
	file *multipart.FileHeader, tenantID uint64, knowledgeID string,
) (string, error) {
	// Generate object name
	ext := filepath.Ext(file.Filename)
	objectName := fmt.Sprintf("%d/%s/%s%s", tenantID, knowledgeID, uuid.New().String(), ext)

	// Open file
	src, err := file.Open()
	if err != nil {
		return "", fmt.Errorf("failed to open file: %w", err)
	}
	defer src.Close()

	// Upload file to MinIO
	_, err = s.client.PutObject(ctx, s.bucketName, objectName, src, file.Size, minio.PutObjectOptions{
		ContentType: file.Header.Get("Content-Type"),
	})
	if err != nil {
		return "", fmt.Errorf("failed to upload file to MinIO: %w", err)
	}

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

// GetFile gets a file from MinIO
func (s *minioFileService) GetFile(ctx context.Context, filePath string) (io.ReadCloser, error) {
	objectName, err := s.parseMinioFilePath(filePath)
	if err != nil {

View on GitHub (pinned to 988cbb0330)

Solutions

  1. Retry the upload request
  2. Ensure the multipart file is not read twice without re-opening
  3. Check server temp storage health
Defensive patterns

Strategy: try-catch

When it happens

Trigger: Thrown at internal/application/service/file/minio.go:133 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/ff43b3b936c23ef2. Report an issue: GitHub.