Description
When creating an import, if the user uploads a file that doesn't match the selected source type (e.g. uploads a CSV but selects XLSX, or vice versa), the import crashes during parsing instead of showing a user-friendly error on the create form.
Steps to reproduce
- Select a target with
sources :csv, :xlsx
- Choose "XLSX" as source type
- Upload a
.csv file
- Submit → crash in
Sources::Xlsx (Creek can't parse a CSV as XLSX)
Same in reverse: select CSV, upload .xlsx → CSV::MalformedCSVError
Expected behavior
The create form should validate that the uploaded file extension and/or MIME type matches the selected source type before saving the import. Display an inline error on the form like "File type does not match selected source (expected .xlsx)".
Suggested approach
Validate in the controller create action (or a before_action):
- Check file extension against source type (
.csv for csv, .xlsx for xlsx, .json for json)
- Optionally check MIME type as a secondary check
- Return 422 with error message rendered on the form
Note: there is already MIME type validation in ImportValidation for allowed content types, but it doesn't cross-check against the selected source type.
Description
When creating an import, if the user uploads a file that doesn't match the selected source type (e.g. uploads a CSV but selects XLSX, or vice versa), the import crashes during parsing instead of showing a user-friendly error on the create form.
Steps to reproduce
sources :csv, :xlsx.csvfileSources::Xlsx(Creek can't parse a CSV as XLSX)Same in reverse: select CSV, upload
.xlsx→CSV::MalformedCSVErrorExpected behavior
The create form should validate that the uploaded file extension and/or MIME type matches the selected source type before saving the import. Display an inline error on the form like "File type does not match selected source (expected .xlsx)".
Suggested approach
Validate in the controller
createaction (or abefore_action):.csvfor csv,.xlsxfor xlsx,.jsonfor json)Note: there is already MIME type validation in
ImportValidationfor allowed content types, but it doesn't cross-check against the selected source type.