instructure/canvas-lms · error · ContentTooLarge
File exceeds # byte limit
Error message
File exceeds #{MAX_FILE_BYTES} byte limit What it means
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.
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.
Example fix
// before
resolve_content(kind: :file, id: huge_pdf.id)
# => ContentTooLarge: File exceeds MAX_FILE_BYTES byte limit
// after
attachment = course.attachments.find(params[:file_id])
if attachment.size.to_i > StudyAssist::MAX_FILE_BYTES
return render json: { error: 'File too large for Study Assist' }, status: :unprocessable_entity
end
resolve_content(kind: :file, id: attachment.id) Defensive patterns
Strategy: validation
Validate before calling
attachment = course.attachments.find_by(id: file_id) return head :unprocessable_entity if attachment.nil? || attachment.size.to_i > StudyAssist::MAX_FILE_BYTES
Try / catch
begin
service.resolve_content(kind: :file, id: file_id)
rescue StudyAssist::ContentTooLarge
render json: { error: 'file_too_large' }, status: :unprocessable_entity
end Prevention
- 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
When it happens
Trigger: resolve_content -> resolve_file with a file_id whose attachment.size exceeds MAX_FILE_BYTES (attachment.size is non-nil).
Common situations: 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.
Understand the failure class
Background: "File too large" / "file size exceeds limit" errors: why libraries cap file sizes and how to fix them — this error's family across 46 libraries.
Related errors
- Attachment verifier token expired: #
- Attachment verifier token id mismatch. token id: #
- Attachment verifier token invalid: #
- failed to reclaim attachment #
- Invalid Attachment
AI-assisted analysis of instructure/canvas-lms@1c9f0bb801 (2026-09-15).
Data as JSON: /api/errors/c02f9197c6e07b5e.
Report an issue: GitHub.
Appendix: source
Thrown at app/services/study_assist.rb:175
page = @course.wiki_pages.not_deleted.find_by(url: page_id)
raise ContentUnavailable, "Page not found" if page.nil?
raise ContentUnavailable, "Page access denied" unless page.grants_right?(@user, :read)
shard_safe_key = shard_safe_cache_key_for(page)
text = Rails.cache.fetch(text_cache_key_for(:page, shard_safe_key), expires_in: TEXT_CACHE_TTL) do
html_to_text(page.body.to_s)
end
Content.new(kind: :page, id: page.id, cache_key_with_version: shard_safe_key, text:)
end
def resolve_file(file_id)
attachment = @course.attachments.find_by(id: file_id)
raise ContentUnavailable, "File not found" if attachment.nil? || attachment.deleted?
raise ContentUnavailable, "File access denied" unless attachment.grants_right?(@user, :read)
raise ContentUnavailable, "File is locked" if attachment.locked_for?(@user, check_policies: true)
raise UnsupportedContentType unless supported_attachment?(attachment)
raise ContentTooLarge, "File exceeds #{MAX_FILE_BYTES} byte limit" if attachment.size && attachment.size > MAX_FILE_BYTES
shard_safe_key = shard_safe_cache_key_for(attachment)
text = Rails.cache.fetch(text_cache_key_for(:file, shard_safe_key), expires_in: TEXT_CACHE_TTL) do
extract_attachment_text(attachment)
end
raise ContentUnavailable, "No text available for file" if text.blank?
Content.new(kind: :file, id: attachment.id, cache_key_with_version: shard_safe_key, text:)
end
def supported_attachment?(attachment)
return true if attachment.content_type&.start_with?("text/")
ACCEPTED_FILE_MIMETYPES.include?(attachment.content_type)
end
def extract_attachment_text(attachment)View on GitHub (pinned to 1c9f0bb801)