{"record":{"id":"ba26e7955b4e788e","repo":"we-promise/sure","slug":"content-too-large","errorCode":"content_too_large","errorMessage":"Content is too large. Maximum size is #{Import.max_csv_size / 1.megabyte}MB.","messagePattern":"Content is too large\\. Maximum size is #(.+?)MB\\.","errorType":"http","errorClass":"Import::Preflight::PreflightError","httpStatus":422,"severity":"error","filePath":"app/models/import/preflight.rb","lineNumber":395,"sourceCode":"        payload: {\n          error: \"content_too_large\",\n          message: \"Content is too large. Maximum size is #{SureImport.max_ndjson_size / 1.megabyte}MB.\"\n        }\n      )\n    end\n\n    def invalid_sure_file_type_response\n      Response.new(\n        status: :unprocessable_entity,\n        payload: {\n          error: \"invalid_file_type\",\n          message: \"Invalid file type. Please upload a Sure NDJSON file.\"\n        }\n      )\n    end\n\n    def raise_response(response)\n      raise PreflightError, response\n    end\n\n    def unsupported_import_type_response\n      Response.new(\n        status: :unprocessable_entity,\n        payload: {\n          error: \"unsupported_import_type\",\n          message: \"Preflight supports CSV import types and SureImport.\"\n        }\n      )\n    end\nend\n","sourceCodeStart":377,"sourceCodeEnd":408,"githubUrl":"https://github.com/we-promise/sure/blob/e69894adb92547273377398c15f45c979cd9416a/app/models/import/preflight.rb#L377-L408","documentation":"Import::Preflight#csv_raw_content_attributes (app/models/import/preflight.rb:200) returns HTTP 422 {error: 'content_too_large'} when the raw_file_content string (the in-body alternative to a multipart file) exceeds Import.max_csv_size, the constant 10MB Import::MAX_CSV_SIZE. The check uses content.bytesize, so it measures bytes, not characters. The same guard runs at import creation (app/controllers/api/v1/imports_controller.rb:96).","triggerScenarios":"POSTing params[:raw_file_content] whose bytesize exceeds 10485760 bytes — e.g. an in-memory CSV built by concatenating several exports into one JSON body.","commonSituations":"Building raw_file_content by concatenating monthly exports; base64-encoding the CSV (adds ~33% and pushes over the cap); multi-byte UTF-8 content whose character count looks under the limit while bytesize is over it.","solutions":["Split the content and send multiple imports, each under 10MB","Send a multipart file instead — same cap, but avoids JSON string overhead","Convert to SureImport NDJSON and tune SURE_IMPORT_MAX_NDJSON_SIZE_MB on self-hosted installs","Self-hosted only: change Import::MAX_CSV_SIZE in app/models/import.rb and redeploy"],"exampleFix":"# Ruby client, before (one giant payload)\nbody = { raw_file_content: years_of_csv } # → 422 content_too_large\n\n# after\nyears_of_csv.bytesize\ntext = years_of_csv\nparts = []\nwhile text.bytesize > 10 * 1024 * 1024\n  cut = text.byteslice(0, 9 * 1024 * 1024).rindex(\"\\n\") || 9 * 1024 * 1024\n  parts << text.byteslice(0, cut)\n  text = text.byteslice((cut + 1)..-1).to_s\nend\nparts << text\nparts.each { |p| post_import(raw_file_content: p) }","handlingStrategy":"validation","validationCode":"MAX_CSV_BYTES = 10 * 1024 * 1024\nraise 'raw_file_content exceeds 10MB' if raw_content.bytesize > MAX_CSV_BYTES\n# split on a newline boundary and send several imports\n","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Check String#bytesize (not length) before sending raw_file_content","Prefer multipart upload to avoid JSON escaping overhead on large bodies","Split on newline boundaries so each part stays a valid CSV"],"tags":["rails","import","csv","request-body","size-limit","http-422"],"backgroundTag":"payload-too-large","analyzedSha":"e69894adb92547273377398c15f45c979cd9416a","analyzedAt":"2026-08-21T18:22:41.165Z","schemaVersion":2},"datasetVersion":"2026-08-21T23:17:16.201Z"}