OrchardCMS/OrchardCore · error · FileStoreException
The file ' ' was rejected.
Error message
The file '{fileCreatingContext.FileName}' was rejected. What it means
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.
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.
Example fix
// before
return FileCreatingResult.Failed();
// after
return FileCreatingResult.Failed("Files of type .exe are not allowed."); Defensive patterns
Strategy: try-catch
Validate before calling
// Pre-check: ensure the extension is allowed by media settings before upload
var ext = Path.GetExtension(fileName);
if (!allowedExtensions.Contains(ext, StringComparer.OrdinalIgnoreCase))
throw new InvalidOperationException($"File type '{ext}' is not allowed."); Try / catch
try
{
await mediaFileStore.CreateFileFromStreamAsync(path, stream);
}
catch (FileStoreException ex)
{
logger.LogWarning(ex, "File {FileName} rejected by media validation", fileName);
// surface ex.Message to the user
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: Uploading file types blocked by media settings; security handlers rejecting suspicious files (e.g. .html, executables); custom IFileStore validation rules failing during bulk imports.
Understand the failure class
Background: Schema validation failed / invalid input schema: payload rejected because its shape doesn't match the expected schema — this error's family across 28 libraries.
Related errors
- The file extension should start with a dot.
- You tried to upload a file that requires
- The media path is invalid.
- This file extension is not allowed
- The 'Default' tenant can't be removed.
AI-assisted analysis of OrchardCMS/OrchardCore@4306c0717f (2026-09-13).
Data as JSON: /api/errors/046da0c8bd27ca6d.
Report an issue: GitHub.
Appendix: source
Thrown at src/OrchardCore/OrchardCore.Media.Abstractions/MediaFileStoreExtensions.cs:38
string contentType = null,
CancellationToken cancellationToken = default)
{
ArgumentNullException.ThrowIfNull(mediaFileStore);
ArgumentNullException.ThrowIfNull(fileCreationService);
ArgumentNullException.ThrowIfNull(path);
ArgumentNullException.ThrowIfNull(stream);
var fileCreatingContext = new FileCreatingContext(path, length, contentType);
await using var fileCreatingResult = await fileCreationService.CreateAsync(
fileCreatingContext,
stream,
leaveOpen: true,
cancellationToken);
if (!fileCreatingResult.Succeeded)
{
throw new FileStoreException(fileCreatingResult.ErrorMessage ?? $"The file '{fileCreatingContext.FileName}' was rejected.");
}
var createdPath = await mediaFileStore.CreateFileFromStreamAsync(path, fileCreatingResult.Stream, overwrite);
var fileInfo = await mediaFileStore.GetFileInfoAsync(createdPath);
await fileCreationService.CreatedAsync(fileInfo, cancellationToken);
return createdPath;
}
}
View on GitHub (pinned to 4306c0717f)