{"record":{"id":"977e413f21475276","repo":"instructure/canvas-lms","slug":"the-downloaded-file-exceeds-the-quota","errorCode":null,"errorMessage":"The downloaded file exceeds the quota.","messagePattern":"The downloaded file exceeds the quota\\.","errorType":"exception","errorClass":"Attachment::OverQuotaError","httpStatus":null,"severity":"error","filePath":"app/models/attachment.rb","lineNumber":2414,"sourceCode":"    {\n      tags: {\n        type: CLONING_ERROR_TYPE\n      },\n      extra: {\n        http_status_code: error.try(:code),\n        body: error.try(:body),\n        url:\n      }.compact\n    }\n  end\n\n  def clone_url(url, duplicate_handling, check_quota, opts = {})\n    Attachment.clone_url_as_attachment(url, attachment: self)\n\n    if check_quota\n      save! # save to calculate attachment size, otherwise self.size is nil\n      if Attachment.over_quota?(opts[:quota_context] || context, size)\n        raise OverQuotaError, t(:over_quota, \"The downloaded file exceeds the quota.\")\n      end\n    end\n\n    self.file_state = \"available\"\n    save!\n\n    # the UI only needs the id from here\n    opts[:progress]&.set_results({ id: })\n\n    handle_duplicates(duplicate_handling || \"overwrite\")\n    nil # the rescue returns true if the file failed and is retryable, nil if successful\n  rescue => e\n    failed_retryable = false\n    self.file_state = \"errored\"\n    self.workflow_state = \"errored\"\n    case e\n    when CanvasHttp::TooManyRedirectsError\n      failed_retryable = true","sourceCodeStart":2396,"sourceCodeEnd":2432,"githubUrl":"https://github.com/instructure/canvas-lms/blob/1c9f0bb8013ed69c4f2efe11fd483025469b7e6c/app/models/attachment.rb#L2396-L2432","documentation":"Attachment#clone_url downloads a remote URL into this attachment. When check_quota is enabled and, after saving to compute size, Attachment.over_quota? reports the context would exceed its storage quota, it raises OverQuotaError with 'The downloaded file exceeds the quota.' The download already happened; the error aborts making the file available.","triggerScenarios":"Calling clone_url (or_clone/clone_to helpers) with check_quota=true on a context whose remaining quota is smaller than the downloaded file's size; importing a large file via submission/import APIs into a nearly full course/account/user quota.","commonSituations":"Course or user storage quota exhausted; institutional account quotas tightened while old imports still run; large media migrations exceeding per-context limits; quota_context passed incorrectly so a tiny quota is checked.","solutions":["Free up storage in the context (delete unneeded files) or raise the quota before retrying","Download a smaller file or skip quota check explicitly if policy allows (check_quota: false)","Pass the correct opts[:quota_context] so the right context's quota is evaluated","Rescue Attachment::OverQuotaError in the controller/job and show a quota-exceeded message with usage details"],"exampleFix":"// before\nattachment.clone_url(url, 'rename', true)\n// after\nbegin\n  attachment.clone_url(url, 'rename', true)\nrescue Attachment::OverQuotaError\n  notify_user_of_quota_exceeded(context)\nend","handlingStrategy":"try-catch","validationCode":"// check remaining quota before initiating download\nused = context.attachments.sum(:size)\nremaining = context.storage_quota - used\nif remaining <= 0 raise Attachment::OverQuotaError\n","typeGuard":null,"tryCatchPattern":"begin\n  attachment.clone_url(url, 'rename', true)\nrescue Attachment::OverQuotaError => e\n  render json: { error: e.message, quota: context.storage_quota }, status: :insufficient_storage\nend","preventionTips":["Monitor quota usage and alert before exhaustion","Validate the source URL's content-length against remaining quota when possible","Pass the correct quota_context for cross-context clones"],"tags":["storage","quota","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"}