we-promise/sure · error · Import::Preflight::PreflightError
file_too_large
file_too_large
Error message
File is too large. Maximum size is #{Import.max_csv_size / 1.megabyte}MB. What it means
Import::Preflight#csv_file_upload_attributes (app/models/import/preflight.rb:189) rejects a multipart CSV upload with HTTP 422 {error: 'file_too_large'} when file.size exceeds Import.max_csv_size, the hard-coded constant Import::MAX_CSV_SIZE = 10.megabytes (app/models/import.rb:35) — there is no ENV override for the CSV cap. Because preflight reads and parses the whole file, size is checked before any parsing runs. The same 10MB guard is enforced again at import creation (app/controllers/api/v1/imports_controller.rb:80).
Source
Thrown at app/models/import/preflight.rb:395
payload: {
error: "content_too_large",
message: "Content is too large. Maximum size is #{SureImport.max_ndjson_size / 1.megabyte}MB."
}
)
end
def invalid_sure_file_type_response
Response.new(
status: :unprocessable_entity,
payload: {
error: "invalid_file_type",
message: "Invalid file type. Please upload a Sure NDJSON file."
}
)
end
def raise_response(response)
raise PreflightError, response
end
def unsupported_import_type_response
Response.new(
status: :unprocessable_entity,
payload: {
error: "unsupported_import_type",
message: "Preflight supports CSV import types and SureImport."
}
)
end
end
View on GitHub (pinned to e69894adb9)
Solutions
- Split the CSV into files under 10MB and run one import per part
- Re-export a narrower date range or drop unneeded columns from the source
- Convert the data to SureImport NDJSON, whose size cap is env-tunable on self-hosted installs (SURE_IMPORT_MAX_NDJSON_SIZE_MB)
- Self-hosted only: edit Import::MAX_CSV_SIZE in app/models/import.rb and redeploy — no ENV knob exists for the CSV cap
Example fix
# before: single 14MB upload → 422 file_too_large
split -b 9m export.csv part_
# after: upload each part under 10MB
for f in part_*; do curl -F "file=@${f};type=text/csv" -H 'X-Api-Key: k' https://app/api/v1/imports; done Defensive patterns
Strategy: validation
Validate before calling
MAX_CSV_BYTES = 10 * 1024 * 1024 # Import::MAX_CSV_SIZE
size = File.size(path)
raise "CSV is #{size} bytes, max #{MAX_CSV_BYTES} — split it" if size > MAX_CSV_BYTES Prevention
- Check File.size before every CSV upload; split exports at ~9MB boundaries on line ends
- Re-export narrower date ranges instead of shipping full history in one file
- Remember the cap applies to the decoded upload — request compression does not help
When it happens
Trigger: POST to the import preflight or import create endpoints with params[:file] larger than 10MB, e.g. a 14MB multi-year bank transaction CSV upload.
Common situations: Full-history CSV exports from banks or brokerages; exports with many unused columns; assuming gzip request compression raises the limit — the server measures the decoded uploaded file, not the transfer size.
Related errors
AI-assisted analysis of we-promise/sure@e69894adb9 (2026-08-21).
Data as JSON: /api/errors/67e5e0802a5c2f84.
Report an issue: GitHub.