{"record":{"id":"046da0c8bd27ca6d","repo":"OrchardCMS/OrchardCore","slug":"the-file-filecreatingcontext-filename-was-rejected","errorCode":null,"errorMessage":"The file '{fileCreatingContext.FileName}' was rejected.","messagePattern":"The file '(.+?)' was rejected\\.","errorType":"exception","errorClass":"FileStoreException","httpStatus":null,"severity":"error","filePath":"src/OrchardCore/OrchardCore.Media.Abstractions/MediaFileStoreExtensions.cs","lineNumber":38,"sourceCode":"        string contentType = null,\n        CancellationToken cancellationToken = default)\n    {\n        ArgumentNullException.ThrowIfNull(mediaFileStore);\n        ArgumentNullException.ThrowIfNull(fileCreationService);\n        ArgumentNullException.ThrowIfNull(path);\n        ArgumentNullException.ThrowIfNull(stream);\n\n        var fileCreatingContext = new FileCreatingContext(path, length, contentType);\n\n        await using var fileCreatingResult = await fileCreationService.CreateAsync(\n            fileCreatingContext,\n            stream,\n            leaveOpen: true,\n            cancellationToken);\n\n        if (!fileCreatingResult.Succeeded)\n        {\n            throw new FileStoreException(fileCreatingResult.ErrorMessage ?? $\"The file '{fileCreatingContext.FileName}' was rejected.\");\n        }\n\n        var createdPath = await mediaFileStore.CreateFileFromStreamAsync(path, fileCreatingResult.Stream, overwrite);\n        var fileInfo = await mediaFileStore.GetFileInfoAsync(createdPath);\n\n        await fileCreationService.CreatedAsync(fileInfo, cancellationToken);\n\n        return createdPath;\n    }\n}\n","sourceCodeStart":20,"sourceCodeEnd":49,"githubUrl":"https://github.com/OrchardCMS/OrchardCore/blob/4306c0717fe573f6fca1b4955909ddab6a192807/src/OrchardCore/OrchardCore.Media.Abstractions/MediaFileStoreExtensions.cs#L20-L49","documentation":"CreateFileFromStreamAsync runs the media file creation pipeline (validation handlers that may inspect/transform the file). If the creation result is not Succeeded and no specific ErrorMessage was provided, it wraps the failure in a FileStoreException with the generic 'was rejected' message.","triggerScenarios":"Uploading/creating a file via IMediaFileStore.CreateFileFromStreamAsync when a registered file creation/validation handler rejects the file (e.g. disallowed extension, blocked content, custom checks) without setting a custom ErrorMessage.","commonSituations":"Uploading file types blocked by media settings; security handlers rejecting suspicious files (e.g. .html, executables); custom IFileStore validation rules failing during bulk imports.","solutions":["Inspect the rejection reason by enabling logging and checking which file creation handler returned Succeeded=false.","Allow the file type in Media settings (allowed file extensions list) if it was blocked incorrectly.","Register a custom IMediaFileVersionProvider/validation adjustment or modify blocking handlers to permit the file.","If the error is from your own handler, set a descriptive ErrorMessage on FileCreatingResult so users get a specific message."],"exampleFix":"// before\nreturn FileCreatingResult.Failed();\n// after\nreturn FileCreatingResult.Failed(\"Files of type .exe are not allowed.\");","handlingStrategy":"try-catch","validationCode":"// Pre-check: ensure the extension is allowed by media settings before upload\nvar ext = Path.GetExtension(fileName);\nif (!allowedExtensions.Contains(ext, StringComparer.OrdinalIgnoreCase))\n    throw new InvalidOperationException($\"File type '{ext}' is not allowed.\");","typeGuard":null,"tryCatchPattern":"try\n{\n    await mediaFileStore.CreateFileFromStreamAsync(path, stream);\n}\ncatch (FileStoreException ex)\n{\n    logger.LogWarning(ex, \"File {FileName} rejected by media validation\", fileName);\n    // surface ex.Message to the user\n}","preventionTips":["Check the media allowed-extensions list before programmatic uploads.","Register custom validation handlers with descriptive error messages.","Log the FileCreatingResult.ErrorMessage to identify the rejecting handler.","Sanitize/validate files client-side before bulk imports."],"tags":["media","file-upload","validation"],"backgroundTag":"schema-validation-failed","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"}