Tencent/WeKnora · error
failed to open file: %w
Error message
failed to open file: %w
What it means
Upload error in s3FileService.SaveFile: opening the uploaded multipart file header (file.Open()) failed before any bytes could be streamed to S3. The %w wraps the OS/temp-file error (e.g., the upload temp file was deleted or is unreadable); it fires client-side of the storage SDK, prior to the PutObject call.
Source
Thrown at internal/application/service/file/s3.go:231
}
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 S3
func (s *s3FileService) SaveFile(ctx context.Context,
file *multipart.FileHeader, tenantID uint64, knowledgeID string,
) (string, error) {
// Generate object name
ext := filepath.Ext(file.Filename)
objectName := fmt.Sprintf("%s%d/%s/%s%s", s.pathPrefix, 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()
// Determine content type
contentType := file.Header.Get("Content-Type")
if contentType == "" {
contentType = utils.GetContentTypeByExt(ext)
}
// Upload file to S3
_, err = s.client.PutObject(ctx, &s3.PutObjectInput{
Bucket: aws.String(s.bucketName),
Key: aws.String(objectName),
Body: src,
ContentLength: aws.Int64(file.Size),
ContentType: aws.String(contentType),
})
if err != nil {View on GitHub (pinned to 988cbb0330)
Solutions
- Retry the upload request
- Avoid double-reading the multipart file without re-opening
- Check server temp storage health
Defensive patterns
Strategy: try-catch
When it happens
Trigger: Thrown at internal/application/service/file/s3.go:231 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/8560e5067abbcd3a.
Report an issue: GitHub.