{"record":{"id":"bc150ece951fa680","repo":"kataras/iris","slug":"multipart-related-body-copy-because-of-iris-confi","errorCode":null,"errorMessage":"multipart related: body copy because of iris.Configuration.DisableBodyConsumptionOnUnmarshal: %w","messagePattern":"multipart related: body copy because of iris\\.Configuration\\.DisableBodyConsumptionOnUnmarshal: %w","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"context/context.go","lineNumber":3069,"sourceCode":"\tif err != nil {\n\t\treturn MultipartRelated{}, err\n\t}\n\n\tif !strings.HasPrefix(contentType, ContentMultipartRelatedHeaderValue) {\n\t\treturn MultipartRelated{}, ErrEmptyForm\n\t}\n\n\tvar (\n\t\tcontentIDs []string\n\t\tcontents   = make(map[string]MultipartRelatedContent)\n\t)\n\n\tif ctx.IsRecordingBody() {\n\t\t// * remember, Request.Body has no Bytes(), we have to consume them first\n\t\t// and after re-set them to the body, this is the only solution.\n\t\tbody, restoreBody, err := GetBody(ctx.request, true)\n\t\tif err != nil {\n\t\t\treturn MultipartRelated{}, fmt.Errorf(\"multipart related: body copy because of iris.Configuration.DisableBodyConsumptionOnUnmarshal: %w\", err)\n\t\t}\n\t\tsetBody(ctx.request, body) // so the ctx.request.Body works\n\t\tdefer restoreBody()        // so the next ctx.GetBody calls work.\n\t}\n\n\tmultipartReader := multipart.NewReader(ctx.request.Body, params[\"boundary\"])\n\tfor {\n\t\tpart, err := multipartReader.NextPart()\n\t\tif err != nil {\n\t\t\tif err == io.EOF {\n\t\t\t\tbreak\n\t\t\t}\n\n\t\t\treturn MultipartRelated{}, fmt.Errorf(\"multipart related: next part: %w\", err)\n\t\t}\n\t\tdefer part.Close()\n\n\t\tb, err := io.ReadAll(part)","sourceCodeStart":3051,"sourceCodeEnd":3087,"githubUrl":"https://github.com/kataras/iris/blob/7bedaf55a0b64bbb2248a5845a2c60d81a30996a/context/context.go#L3051-L3087","documentation":"Returned by ReadMultipartRelated when the request body is being recorded (IsRecordingBody, typically because DisableBodyConsumptionOnUnmarshal is enabled) and the internal GetBody copy step fails. The error wraps the underlying copy failure and means the body could not be buffered so the multipart reader cannot safely be constructed from a re-readable stream.","triggerScenarios":"ctx.ReadMultipartRelated on a request with body recording/DisableBodyConsumptionOnUnmarshal where GetBody(ctx.request, true) fails (e.g. read error, client aborted, malformed stream).","commonSituations":"Large multipart/related uploads hitting body-size limits or client disconnects mid-transfer; proxy interruptions; misconfigured body-size limits in servers or gateways.","solutions":["Inspect the wrapped underlying error (%w) for the real cause (timeout, reset, size limit).","Disable body recording for large uploads or raise the body limit configuration.","Ask the client to retry if the connection reset mid-upload; verify client aborts.","Test with a smaller payload to separate size-related failures from encoding problems."],"exampleFix":"// before\nmr, err := ctx.ReadMultipartRelated()\nif err != nil { return err }\n// after\nmr, err := ctx.ReadMultipartRelated()\nif err != nil {\n    if strings.Contains(err.Error(), \"body copy\") {\n        app.Logger().Warn(\"multipart body copy failed, likely aborted upload\")\n    }\n    ctx.StatusCode(iris.StatusBadRequest)\n    return err\n}","handlingStrategy":"try-catch","validationCode":null,"typeGuard":"func isBodyCopyFailure(err error) bool {\n    return strings.Contains(err.Error(), \"body copy because of iris.Configuration\")\n}","tryCatchPattern":"mr, err := ctx.ReadMultipartRelated()\nif err != nil {\n    if strings.Contains(err.Error(), \"body copy\") {\n        ctx.StatusCode(iris.StatusBadRequest)\n        return fmt.Errorf(\"upload aborted or unreadable: %w\", err)\n    }\n    return err\n}","preventionTips":["Avoid recording the body for very large multipart uploads","Set reasonable body-size limits and timeouts on the server","Log the wrapped inner error to find the real transport cause"],"tags":["go","iris","multipart","request-body"],"backgroundTag":"request-body-read-failed","analyzedSha":"7bedaf55a0b64bbb2248a5845a2c60d81a30996a","analyzedAt":"2026-08-30T20:38:16.250Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}