{"record":{"id":"6085c503a5d7de92","repo":"OrchardCMS/OrchardCore","slug":"the-media-path-is-invalid","errorCode":null,"errorMessage":"The media path is invalid.","messagePattern":"The media path is invalid\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/OrchardCore.Modules/OrchardCore.Lists/RemotePublishing/MetaWeblogHandler.cs","lineNumber":164,"sourceCode":"            var result = await MetaWeblogNewMediaObjectAsync(\n                Convert.ToString(context.RpcMethodCall.Params[1].Value),\n                Convert.ToString(context.RpcMethodCall.Params[2].Value),\n                (XRpcStruct)context.RpcMethodCall.Params[3].Value);\n            context.RpcMethodResponse = new XRpcMethodResponse().Add(result);\n        }\n    }\n\n    private async Task<XRpcStruct> MetaWeblogNewMediaObjectAsync(string userName, string password, XRpcStruct file)\n    {\n        var user = await ValidateUserAsync(userName, password);\n\n        var name = file.Optional<string>(\"name\");\n        var bits = file.Optional<byte[]>(\"bits\");\n\n        var normalizedPath = _mediaFileStore.NormalizePath(name);\n        if (string.IsNullOrWhiteSpace(normalizedPath))\n        {\n            throw new InvalidOperationException(S[\"The media path is invalid.\"].Value);\n        }\n\n        var pathSegments = normalizedPath.Split('/', StringSplitOptions.RemoveEmptyEntries);\n        if (pathSegments.Any(segment => segment is \".\" or \"..\"))\n        {\n            throw new InvalidOperationException(S[\"The media path is invalid.\"].Value);\n        }\n\n        var fileName = pathSegments[^1];\n        var directoryName = string.Join('/', pathSegments[..^1]);\n        var filePath = _mediaFileStore.Combine(directoryName, fileName);\n\n        if (!await _authorizationService.AuthorizeAsync(user, MediaPermissions.ManageMedia)\n            || !await _authorizationService.AuthorizeAsync(user, MediaPermissions.ManageMediaFolder, (object)(directoryName ?? string.Empty)))\n        {\n            throw new InvalidOperationException(S[\"Not authorized to upload media.\"].Value);\n        }\n","sourceCodeStart":146,"sourceCodeEnd":182,"githubUrl":"https://github.com/OrchardCMS/OrchardCore/blob/4306c0717fe573f6fca1b4955909ddab6a192807/src/OrchardCore.Modules/OrchardCore.Lists/RemotePublishing/MetaWeblogHandler.cs#L146-L182","documentation":"MetaWeblog's newMediaObject (XML-RPC media upload) normalizes the provided media file name via IMediaFileStore.NormalizePath and rejects empty/whitespace results with 'The media path is invalid.'. This validates that a usable, non-empty target path was supplied before writing to the Media File Store.","triggerScenarios":"Sending an XML-RPC metaWeblog.newMediaObject request whose media struct has a missing, null, or empty/whitespace 'name' field.","commonSituations":"Blog clients (Open Live Writer, MarsEdit-like tools) configured to upload media without a filename; hand-written XML-RPC calls omitting 'name'; clients sending only 'bits'.","solutions":["Ensure the media struct in the newMediaObject request includes a non-empty 'name' field with the target file name/path","Fix the blogging client's media upload settings so it sends file names","If calling the API directly, pass e.g. 'image.png' or 'subfolder/image.png' as name"],"exampleFix":"// before\nvar file = new { bits = File.ReadAllBytes(\"img.png\") };\n// after\nvar file = new { name = \"img.png\", bits = File.ReadAllBytes(\"img.png\") };","handlingStrategy":"validation","validationCode":"if (string.IsNullOrWhiteSpace(media.name)) throw new ArgumentException(\"newMediaObject requires a non-empty 'name'\");","typeGuard":"bool HasValidMediaName(IDictionary<string, object> file) => file.TryGetValue(\"name\", out var n) && n is string s && !string.IsNullOrWhiteSpace(s);","tryCatchPattern":"try { await client.NewMediaObjectAsync(blogId, user, pass, media); } catch (InvalidOperationException ex) when (ex.Message.Contains(\"media path is invalid\")) { FixMediaNameAndRetry(media); }","preventionTips":["Always populate both 'name' and 'bits' in the media struct","Validate the request body before sending XML-RPC calls","Check blogging client settings for media upload naming","Test uploads with a simple image after configuring a new client"],"tags":["xmlrpc","media","metaweblog","validation"],"backgroundTag":"empty-required-field","analyzedSha":"4306c0717fe573f6fca1b4955909ddab6a192807","analyzedAt":"2026-09-13T17:41:05.024Z","contentChangedAt":"2026-09-13T17:41:05.024Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}