{"record":{"id":"ee34cb78f3fc9e39","repo":"litedb-org/LiteDB","slug":"filename-ee34cb","errorCode":null,"errorMessage":"filename","messagePattern":"filename","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"LiteDB/Client/Storage/LiteStorage.cs","lineNumber":157,"sourceCode":"        /// <summary>\n        /// Upload a file based on stream data\n        /// </summary>\n        public LiteFileInfo<TFileId> Upload(TFileId id, string filename, Stream stream, BsonDocument metadata = null)\n        {\n            using (var writer = this.OpenWrite(id, filename, metadata))\n            {\n                stream.CopyTo(writer);\n\n                return writer.FileInfo;\n            }\n        }\n\n        /// <summary>\n        /// Upload a file based on file system data\n        /// </summary>\n        public LiteFileInfo<TFileId> Upload(TFileId id, string filename)\n        {\n            if (filename.IsNullOrWhiteSpace()) throw new ArgumentNullException(nameof(filename));\n\n            using (var stream = File.OpenRead(filename))\n            {\n                return this.Upload(id, Path.GetFileName(filename), stream);\n            }\n        }\n\n        /// <summary>\n        /// Update metadata on a file. File must exist.\n        /// </summary>\n        public bool SetMetadata(TFileId id, BsonDocument metadata)\n        {\n            var file = this.FindById(id);\n\n            if (file == null) return false;\n\n            file.Metadata = metadata ?? new BsonDocument();\n","sourceCodeStart":139,"sourceCodeEnd":175,"githubUrl":"https://github.com/litedb-org/LiteDB/blob/f906a5f850678719e39a39a006cb66dcae563cfa/LiteDB/Client/Storage/LiteStorage.cs#L139-L175","documentation":"ArgumentNullException thrown by LiteStorage<TFileId>.Upload(TFileId id, string filename) when the filename argument is null, empty, or whitespace. This overload reads a file from disk via File.OpenRead, so a valid path is required. The check uses IsNullOrWhiteSpace.","triggerScenarios":"Calling storage.Upload(id, null), storage.Upload(id, \"\"), or storage.Upload(id, \"  \"). Also when the filename comes from user input or a form upload that was not populated.","commonSituations":"Web API receiving a file path that the client omitted. A configuration or environment variable for the source path being unset. Path construction from nullable components.","solutions":["Validate the filename/path is non-empty and the file exists before calling Upload.","Use File.Exists check before the upload call.","Return a validation error to the caller if the path is missing."],"exampleFix":"// before\nstorage.Upload(id, uploadedPath); // uploadedPath may be null\n// after\nif (string.IsNullOrWhiteSpace(uploadedPath) || !File.Exists(uploadedPath))\n    throw new ArgumentException(\"Valid file path required.\");\nstorage.Upload(id, uploadedPath);","handlingStrategy":"validation","validationCode":"if (string.IsNullOrWhiteSpace(filename) || !File.Exists(filename))\n    throw new ArgumentException(\"A valid file path is required.\", nameof(filename));\nstorage.Upload(id, filename);","typeGuard":"static bool IsValidUploadPath(string f) =>\n    !string.IsNullOrWhiteSpace(f) && File.Exists(f);","tryCatchPattern":"try\n{\n    storage.Upload(id, path);\n}\ncatch (ArgumentNullException ex) when (ex.ParamName == \"filename\")\n{\n    // path was null/empty; prompt the user or use a default\n    throw;\n}","preventionTips":["Validate the source file path with File.Exists before calling Upload.","Check for null/empty paths at the API boundary.","Use Path.Combine to construct paths from validated components."],"tags":["argument-null","file-storage","upload","validation"],"backgroundTag":null,"analyzedSha":"f906a5f850678719e39a39a006cb66dcae563cfa","analyzedAt":"2026-08-13T21:56:30.148Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}