OrchardCMS/OrchardCore · error · FileStoreException
Cannot create file
Error message
Cannot create file '{path}' What it means
After PutObjectAsync completes, CreateFileFromStreamAsync checks response.IsSuccessful(); a non-successful response raises FileStoreException 'Cannot create file'. Additionally, any AmazonS3Exception during upload is wrapped as 'Cannot create file ..., S3 service threw an exception'. It signals the upload to S3 failed.
Solutions
- Read the S3 error message (or inner exception) and fix credentials/IAM s3:PutObject permissions.
- Verify BucketName and region configuration are correct and the bucket exists.
- Ensure the input stream is positioned at 0 and not disposed before upload.
- Retry failed uploads with backoff; use multipart/TransferUtility for large files.
Example fix
// before
using var stream = File.OpenRead(localPath);
await fileStore.CreateFileFromStreamAsync(name, stream);
// after
using var stream = File.OpenRead(localPath);
try
{
await fileStore.CreateFileFromStreamAsync(name, stream, overwrite: true);
}
catch (FileStoreException ex)
{
_logger.LogError(ex, "Upload of '{Name}' failed: {Msg}", name, ex.Message);
throw;
} Defensive patterns
Strategy: retry
Validate before calling
if (string.IsNullOrEmpty(_awsOptions.BucketName))
{
throw new InvalidOperationException("S3 bucket name is not configured.");
}
if (!stream.CanRead)
{
throw new InvalidOperationException("Input stream is not readable.");
} Try / catch
try
{
await fileStore.CreateFileFromStreamAsync(path, stream);
}
catch (FileStoreException ex)
{
_logger.LogError(ex, "S3 upload failed: {Message}", ex.InnerException?.Message ?? ex.Message);
throw;
} Prevention
- Grant IAM s3:PutObject on the target prefix.
- Reset stream position to 0 and keep it open during upload.
- Use TransferUtility/multipart for large files.
- Retry uploads with exponential backoff on transient failures.
When it happens
Trigger: CreateFileFromStreamAsync when PutObjectAsync returns a failed response or throws: AccessDenied, bucket not found, network interruption, payload issues, invalid credentials.
Common situations: IAM missing s3:PutObject, wrong bucket name, upload interrupted by network outage, request body too large or stream already consumed, throttling under heavy media upload load.
Understand the failure class
Background: "failed to write file", "Could not save figure", "Error saving remote file" — file write failed: causes and fixes across languages and libraries — this error's family across 38 libraries.
Related errors
- Error creating directory
- Error deleting file
- Error accessing file
- Error while copying file
- Error getting file stream for
AI-assisted analysis of OrchardCMS/OrchardCore@4306c0717f (2026-09-13).
Data as JSON: /api/errors/8be0d146cb91ac38.
Report an issue: GitHub.
Appendix: source
Thrown at src/OrchardCore/OrchardCore.FileStorage.AmazonS3/AwsFileStorage.cs:300
Prefix = this.Combine(_basePrefix, path),
});
if (listObjects.S3Objects?.Count > 0)
{
throw new ExistsFileStoreException($"Cannot create file '{path}' because it already exists.");
}
}
var response = await _amazonS3Client.PutObjectAsync(new PutObjectRequest
{
BucketName = _options.BucketName,
Key = this.Combine(_basePrefix, path),
InputStream = inputStream,
});
if (!response.IsSuccessful())
{
throw new FileStoreException($"Cannot create file '{path}'");
}
}
catch (AmazonS3Exception ex)
{
throw new FileStoreException($"Cannot create file '{path}', S3 service threw an exception: {ex.Message}");
}
return path;
}
private static string NormalizePrefix(string prefix)
{
prefix = prefix.Trim('/') + '/';
if (prefix.Length == 1)
{
return string.Empty;
}
View on GitHub (pinned to 4306c0717f)