{"record":{"id":"7efde9a1727d159c","repo":"gofiber/fiber","slug":"file-failed-to-open-file","errorCode":null,"errorMessage":"file: failed to open file","messagePattern":"file: failed to open file","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"error.go","lineNumber":103,"sourceCode":"\t// SyntaxError is a description of a JSON syntax error.\n\tSyntaxError = json.SyntaxError\n\n\t// UnmarshalTypeError describes a JSON value that was\n\t// not appropriate for a value of a specific Go type.\n\tUnmarshalTypeError = json.UnmarshalTypeError\n\n\t// UnsupportedTypeError is returned by Marshal when attempting\n\t// to encode an unsupported value type.\n\tUnsupportedTypeError = json.UnsupportedTypeError\n\n\t// UnsupportedValueError exposes json.UnsupportedValueError to describe unsupported values encountered during encoding.\n\tUnsupportedValueError = json.UnsupportedValueError\n)\n\n// File errors\nvar (\n\tErrFileHeaderNil = errors.New(\"file: file header is nil\")\n\tErrFileOpen      = errors.New(\"file: failed to open file\")\n\tErrFileRead      = errors.New(\"file: failed to read file\")\n\tErrFileStore     = errors.New(\"file: failed to store file\")\n)\n","sourceCodeStart":85,"sourceCodeEnd":107,"githubUrl":"https://github.com/gofiber/fiber/blob/a105acad6c1e4576a77f01e02973f67e962bb58d/error.go#L85-L107","documentation":"ErrFileOpen is returned by DefaultCtx.SaveFileToStorage (ctx.go:572) when (*multipart.FileHeader).Open() fails. The error is wrapped as fmt.Errorf(\"%w: %q: %w\", ErrFileOpen, fileheader.Filename, err) so the filename and underlying cause are preserved. SaveFile (disk path) does not produce this error because fasthttp.SaveMultipartFile handles open internally.","triggerScenarios":"Calling c.SaveFileToStorage(fh, path, storage) where fh.Open() returns an error, e.g. when the underlying multipart part has been consumed already, the temp backing was evicted, or the OS rejected the open. ctx.go:569-573 wraps and returns it.","commonSituations":"Re-reading the same FileHeader after a prior Open consumed the part; very large uploads whose temp files were reaped by the OS; custom storage drivers in test environments that fail to materialize the part.","solutions":["Do not call SaveFileToStorage twice on the same FileHeader without re-opening; instead open once and copy to multiple destinations.","Inspect the wrapped underlying error with errors.Unwrap to find the OS-level cause (e.g. ENOENT on the temp file).","Increase the temp-file lifetime / disk space for large uploads and ensure BodyLimit (ctx.go:579) is large enough to accept the body."],"exampleFix":"// before\nreturn c.SaveFileToStorage(fh, key, storage)\n// after\nf, err := fh.Open()\nif err != nil {\n    return fmt.Errorf(\"open upload: %w\", err)\n}\ndefer f.Close()\n// copy f to each destination explicitly","handlingStrategy":"try-catch","validationCode":"// Open the FileHeader once and copy to each destination so SaveFileToStorage\n// never sees an already-consumed part.\nf, err := fh.Open()\nif err != nil {\n    return fmt.Errorf(\"open upload: %w\", err)\n}\ndefer f.Close()","typeGuard":null,"tryCatchPattern":"if err := c.SaveFileToStorage(fh, key, storage); err != nil {\n    if errors.Is(err, fiber.ErrFileOpen) {\n        // inspect the wrapped cause with errors.Unwrap / errors.As\n        return c.Status(fiber.StatusInternalServerError).SendString(\"upload open failed\")\n    }\n    return err\n}","preventionTips":["Do not call SaveFileToStorage twice on the same FileHeader; open once and copy.","Increase temp-file lifetime and disk space for very large uploads.","Use errors.Unwrap to find the OS-level cause behind the wrapped error."],"tags":["file","upload","multipart","storage","io"],"backgroundTag":null,"analyzedSha":"a105acad6c1e4576a77f01e02973f67e962bb58d","analyzedAt":"2026-08-11T17:33:26.942Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}