{"record":{"id":"7989b27dfaadc40b","repo":"Tencent/WeKnora","slug":"failed-to-upload-file-to-tos-w","errorCode":null,"errorMessage":"failed to upload file to TOS: %w","messagePattern":"failed to upload file to TOS: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/application/service/file/tos.go","lineNumber":199,"sourceCode":"\tif err != nil {\n\t\treturn \"\", fmt.Errorf(\"failed to open file: %w\", err)\n\t}\n\tdefer src.Close()\n\n\tcontentType := file.Header.Get(\"Content-Type\")\n\tif contentType == \"\" {\n\t\tcontentType = utils.GetContentTypeByExt(ext)\n\t}\n\t_, err = s.client.PutObjectV2(ctx, &tos.PutObjectV2Input{\n\t\tPutObjectBasicInput: tos.PutObjectBasicInput{\n\t\t\tBucket:      s.bucketName,\n\t\t\tKey:         objectName,\n\t\t\tContentType: contentType,\n\t\t},\n\t\tContent: src,\n\t})\n\tif err != nil {\n\t\treturn \"\", fmt.Errorf(\"failed to upload file to TOS: %w\", err)\n\t}\n\n\treturn fmt.Sprintf(\"tos://%s/%s\", s.bucketName, objectName), nil\n}\n\nfunc (s *tosFileService) SaveBytes(ctx context.Context, data []byte, tenantID uint64, fileName string, temp bool) (string, error) {\n\tsafeName, err := utils.SafeFileName(fileName)\n\tif err != nil {\n\t\treturn \"\", fmt.Errorf(\"invalid file name: %w\", err)\n\t}\n\text := filepath.Ext(safeName)\n\treader := bytes.NewReader(data)\n\n\ttargetBucket := s.bucketName\n\tobjectName := joinTOSObjectKey(\n\t\ts.pathPrefix,\n\t\tfmt.Sprintf(\"%d\", tenantID),\n\t\t\"exports\",","sourceCodeStart":181,"sourceCodeEnd":217,"githubUrl":"https://github.com/Tencent/WeKnora/blob/988cbb03305e055d8ebb7d46d9ac6cc0803cd074/internal/application/service/file/tos.go#L181-L217","documentation":"TOS PutObjectV2 failed while uploading the opened file (content type from header or extension fallback) to the generated joined object key, so the object was not stored; permissions, quota, or connectivity causes are wrapped in the error.","triggerScenarios":"Thrown at internal/application/service/file/tos.go:199 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Check TOS credentials and write permissions","Verify bucket quota and network egress","Retry the upload; the generated key makes retries idempotent-safe"],"exampleFix":null,"handlingStrategy":"retry","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"}