{"record":{"id":"8560e5067abbcd3a","repo":"Tencent/WeKnora","slug":"failed-to-open-file-w-8560e5","errorCode":null,"errorMessage":"failed to open file: %w","messagePattern":"failed to open file: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/application/service/file/s3.go","lineNumber":231,"sourceCode":"\t}\n\tif err := utils.SafeObjectKey(parts[1]); err != nil {\n\t\treturn \"\", fmt.Errorf(\"invalid file path: %w\", err)\n\t}\n\treturn parts[1], nil\n}\n\n// SaveFile saves a file to S3\nfunc (s *s3FileService) SaveFile(ctx context.Context,\n\tfile *multipart.FileHeader, tenantID uint64, knowledgeID string,\n) (string, error) {\n\t// Generate object name\n\text := filepath.Ext(file.Filename)\n\tobjectName := fmt.Sprintf(\"%s%d/%s/%s%s\", s.pathPrefix, tenantID, knowledgeID, uuid.New().String(), ext)\n\n\t// Open file\n\tsrc, err := file.Open()\n\tif err != nil {\n\t\treturn \"\", fmt.Errorf(\"failed to open file: %w\", err)\n\t}\n\tdefer src.Close()\n\n\t// Determine content type\n\tcontentType := file.Header.Get(\"Content-Type\")\n\tif contentType == \"\" {\n\t\tcontentType = utils.GetContentTypeByExt(ext)\n\t}\n\n\t// Upload file to S3\n\t_, err = s.client.PutObject(ctx, &s3.PutObjectInput{\n\t\tBucket:        aws.String(s.bucketName),\n\t\tKey:           aws.String(objectName),\n\t\tBody:          src,\n\t\tContentLength: aws.Int64(file.Size),\n\t\tContentType:   aws.String(contentType),\n\t})\n\tif err != nil {","sourceCodeStart":213,"sourceCodeEnd":249,"githubUrl":"https://github.com/Tencent/WeKnora/blob/988cbb03305e055d8ebb7d46d9ac6cc0803cd074/internal/application/service/file/s3.go#L213-L249","documentation":"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.","triggerScenarios":"Thrown at internal/application/service/file/s3.go:231 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Retry the upload request","Avoid double-reading the multipart file without re-opening","Check server temp storage health"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"988cbb03305e055d8ebb7d46d9ac6cc0803cd074","analyzedAt":"2026-09-02T14:41:08.344Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}