Tencent/WeKnora · error

failed to open file: %w

Error message

failed to open file: %w

What it means

Upload error in tosFileService.SaveFile: file.Open() on the received multipart.FileHeader failed, so the file content could never be read for the TOS PUT. The %w carries the underlying local I/O error; it is raised before any object-key upload request is made.

Source

Thrown at internal/application/service/file/tos.go:182

	parts := strings.SplitN(rest, "/", 2)
	if len(parts) != 2 || parts[0] == "" || parts[1] == "" {
		return "", "", fmt.Errorf("invalid TOS file path: %s", filePath)
	}
	return parts[0], parts[1], nil
}

func (s *tosFileService) SaveFile(ctx context.Context, file *multipart.FileHeader, tenantID uint64, knowledgeID string) (string, error) {
	ext := filepath.Ext(file.Filename)
	objectName := joinTOSObjectKey(
		s.pathPrefix,
		fmt.Sprintf("%d", tenantID),
		knowledgeID,
		uuid.New().String()+ext,
	)

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

	contentType := file.Header.Get("Content-Type")
	if contentType == "" {
		contentType = utils.GetContentTypeByExt(ext)
	}
	_, err = s.client.PutObjectV2(ctx, &tos.PutObjectV2Input{
		PutObjectBasicInput: tos.PutObjectBasicInput{
			Bucket:      s.bucketName,
			Key:         objectName,
			ContentType: contentType,
		},
		Content: src,
	})
	if err != nil {
		return "", fmt.Errorf("failed to upload file to TOS: %w", err)
	}

View on GitHub (pinned to 988cbb0330)

Solutions

  1. Retry the upload request
  2. Avoid re-reading the multipart handle without re-opening
  3. Check server temp storage health
Defensive patterns

Strategy: try-catch

When it happens

Trigger: Thrown at internal/application/service/file/tos.go:182 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/11128b60b6fe049d. Report an issue: GitHub.