{"record":{"id":"2ddbc4e25f948d57","repo":"Tencent/WeKnora","slug":"failed-to-upload-file-to-s3-w","errorCode":null,"errorMessage":"failed to upload file to S3: %w","messagePattern":"failed to upload file to S3: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/application/service/file/s3.go","lineNumber":250,"sourceCode":"\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 {\n\t\treturn \"\", fmt.Errorf(\"failed to upload file to S3: %w\", err)\n\t}\n\n\treturn fmt.Sprintf(\"s3://%s/%s\", s.bucketName, objectName), nil\n}\n\n// GetFile gets a file from S3\nfunc (s *s3FileService) GetFile(ctx context.Context, filePath string) (io.ReadCloser, error) {\n\tobjectName, err := s.parseS3FilePath(filePath)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\n\tresp, err := s.client.GetObject(ctx, &s3.GetObjectInput{\n\t\tBucket: aws.String(s.bucketName),\n\t\tKey:    aws.String(objectName),\n\t})\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to get file from S3: %w\", err)","sourceCodeStart":232,"sourceCodeEnd":268,"githubUrl":"https://github.com/Tencent/WeKnora/blob/988cbb03305e055d8ebb7d46d9ac6cc0803cd074/internal/application/service/file/s3.go#L232-L268","documentation":"S3 PutObject failed while uploading the opened file (content type from header or extension fallback) to the generated prefixed object key, so the object was not stored; permissions, size limits, or connectivity failures are wrapped for the caller.","triggerScenarios":"Thrown at internal/application/service/file/s3.go:250 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Check S3 credentials and write permissions","Verify bucket quota and object size limits","Retry the upload; the key is fresh so retries are 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"}