{"record":{"id":"c02f9197c6e07b5e","repo":"instructure/canvas-lms","slug":"file-exceeds-max-file-bytes-byte-limit","errorCode":null,"errorMessage":"File exceeds #{MAX_FILE_BYTES} byte limit","messagePattern":"File exceeds #(.+?) byte limit","errorType":"validation","errorClass":"ContentTooLarge","httpStatus":null,"severity":"error","filePath":"app/services/study_assist.rb","lineNumber":175,"sourceCode":"      page = @course.wiki_pages.not_deleted.find_by(url: page_id)\n      raise ContentUnavailable, \"Page not found\" if page.nil?\n      raise ContentUnavailable, \"Page access denied\" unless page.grants_right?(@user, :read)\n\n      shard_safe_key = shard_safe_cache_key_for(page)\n      text = Rails.cache.fetch(text_cache_key_for(:page, shard_safe_key), expires_in: TEXT_CACHE_TTL) do\n        html_to_text(page.body.to_s)\n      end\n\n      Content.new(kind: :page, id: page.id, cache_key_with_version: shard_safe_key, text:)\n    end\n\n    def resolve_file(file_id)\n      attachment = @course.attachments.find_by(id: file_id)\n      raise ContentUnavailable, \"File not found\" if attachment.nil? || attachment.deleted?\n      raise ContentUnavailable, \"File access denied\" unless attachment.grants_right?(@user, :read)\n      raise ContentUnavailable, \"File is locked\" if attachment.locked_for?(@user, check_policies: true)\n      raise UnsupportedContentType unless supported_attachment?(attachment)\n      raise ContentTooLarge, \"File exceeds #{MAX_FILE_BYTES} byte limit\" if attachment.size && attachment.size > MAX_FILE_BYTES\n\n      shard_safe_key = shard_safe_cache_key_for(attachment)\n      text = Rails.cache.fetch(text_cache_key_for(:file, shard_safe_key), expires_in: TEXT_CACHE_TTL) do\n        extract_attachment_text(attachment)\n      end\n\n      raise ContentUnavailable, \"No text available for file\" if text.blank?\n\n      Content.new(kind: :file, id: attachment.id, cache_key_with_version: shard_safe_key, text:)\n    end\n\n    def supported_attachment?(attachment)\n      return true if attachment.content_type&.start_with?(\"text/\")\n\n      ACCEPTED_FILE_MIMETYPES.include?(attachment.content_type)\n    end\n\n    def extract_attachment_text(attachment)","sourceCodeStart":157,"sourceCodeEnd":193,"githubUrl":"https://github.com/instructure/canvas-lms/blob/1c9f0bb8013ed69c4f2efe11fd483025469b7e6c/app/services/study_assist.rb#L157-L193","documentation":"StudyAssist raises ContentTooLarge in resolve_file when an Attachment the user asked to analyze is larger than MAX_FILE_BYTES. Text extraction on very large files would be slow and expensive, so the service refuses up front. This is a deliberate guard, not a failure of extraction.","triggerScenarios":"resolve_content -> resolve_file with a file_id whose attachment.size exceeds MAX_FILE_BYTES (attachment.size is non-nil).","commonSituations":"Students pointing StudyAssist at long recorded transcripts, large textbook PDFs, or media-heavy uploads attached to a course; a course where the attachment upload limit is larger than the StudyAssist analysis limit.","solutions":["Check the file size before calling the service and reject/truncate the request client-side: attachment.size <= StudyAssist::MAX_FILE_BYTES.","Split the content into smaller files or analyze a subset of pages and re-run.","If this limit is genuinely too small for your use case, raise MAX_FILE_BYTES in an ops-sanctioned change, accepting the longer LLM processing time."],"exampleFix":"// before\nresolve_content(kind: :file, id: huge_pdf.id)\n# => ContentTooLarge: File exceeds MAX_FILE_BYTES byte limit\n\n// after\nattachment = course.attachments.find(params[:file_id])\nif attachment.size.to_i > StudyAssist::MAX_FILE_BYTES\n  return render json: { error: 'File too large for Study Assist' }, status: :unprocessable_entity\nend\nresolve_content(kind: :file, id: attachment.id)","handlingStrategy":"validation","validationCode":"attachment = course.attachments.find_by(id: file_id)\nreturn head :unprocessable_entity if attachment.nil? || attachment.size.to_i > StudyAssist::MAX_FILE_BYTES","typeGuard":null,"tryCatchPattern":"begin\n  service.resolve_content(kind: :file, id: file_id)\nrescue StudyAssist::ContentTooLarge\n  render json: { error: 'file_too_large' }, status: :unprocessable_entity\nend","preventionTips":["Check attachment.size against StudyAssist::MAX_FILE_BYTES before invoking the service","Enforce an upload limit no larger than the analysis limit so the two never disagree","Show file size limits in the UI before the user selects a file"],"tags":["file-size","limits","attachments"],"backgroundTag":"file-size-limit-exceeded","analyzedSha":"1c9f0bb8013ed69c4f2efe11fd483025469b7e6c","analyzedAt":"2026-09-15T20:33:18.891Z","contentChangedAt":"2026-09-15T20:33:18.891Z","schemaVersion":2},"datasetVersion":"2026-09-23T02:17:17.105Z"}