Skip to content

upload-size-error - Add feature - #10382

Open
Mushir-Ali wants to merge 3 commits into
refined-github:mainfrom
Mushir-Ali:upload-size-error
Open

Mushir-Ali wants to merge 3 commits into
refined-github:mainfrom
Mushir-Ali:upload-size-error

Conversation

@Mushir-Ali

@Mushir-Ali Mushir-Ali commented Nov 7, 2026 •

Copy link
Copy Markdown

Closes #10347

What it does

Listens to the drop event on comment fields (tested with drag and drop) and checks the size of each dropped file. If a file is over GitHub’s 10 MB limit, it shows a toast with the file name, its size (the actual size of the file), and a link to GitHub’s docs on upload limits, instead of GitHub silently inserting <!-- Failed to upload -->.

Only the drop event is handled for now, the file picker and paste go through a different path. Would love to work upon them too, if needed.

Test URLs

#10347
(Any page with a comment box, drag and drop a file over 10 MB.)

Screenshot

Toast shown when dropping an oversized file

@Mushir-Ali
Mushir-Ali marked this pull request as ready for review November 7, 2026 13:10
Comment thread source/features/upload-size-error.tsx Outdated
}

function init(signal: AbortSignal): void {
delegate('textarea', 'input', onInput, {signal});

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not what my comment suggested, you can listen to the drop event and read the file size instead of waiting for the failure in the field.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Totally understandable... I’ll switch to the drop event and check the file size directly (as updated). Should I use a flat 10 MB threshold, or the per-type limits from the docs (10 MB for images/videos, 25 MB for other files)?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've updated the code according to the drop event functionality, with a size check of 10 MB, added the screenshot in the required manner and updated the readme.md

@github-actions github-actions Bot closed this Nov 7, 2026
@github-actions

github-actions Bot commented Nov 7, 2026

Copy link
Copy Markdown

All PRs must include screenshots showing the changes or fixes. This looks like an AI-generated PR, "tests pass" is not an excuse.

Next steps:

  1. Update the PR body with a screenshot/video/gif of the working PR.
  2. Wait for a human to review the PR and reopen it.

Tips:

  • Do not open more PRs until this one is reopened and merged.
  • Don't waste your tokens on junk PRs that won't be accepted.
  • Don't waste your tokens on junk comments that nobody reads.

@Mushir-Ali

Copy link
Copy Markdown
Author

Screenshot of the working toast is in the PR body. The bot closed this during a description edit, when i was changing the screenshot while editing the description of the PR, could you reopen it ?

@fregante fregante reopened this Nov 7, 2026
@Mushir-Ali
Mushir-Ali requested a review from fregante November 7, 2026 19:00
@kidonng

kidonng commented Nov 9, 2026 •

Copy link
Copy Markdown
Member

The docs says the limit is not a blanket 10MB:

The maximum file size is:

  • 10MB for images and gifs
  • 10MB for videos uploaded to a repository owned by a user or organization on a free GitHub plan
  • 100MB for videos uploaded to a repository owned by a user or organization on a paid GitHub plan
  • 25MB for all other files

@Mushir-Ali

Copy link
Copy Markdown
Author

@kidonng That's accurate, limit is not a flat 10MB. Would you like me to create a mapping according to the file type in the drop handler, notably 10MB for images/gifs/videos, and 25MB for other files, by showing the respective limits in the error toast. Also i'll leave the paid plan 100MB video case out now (otherwise i need to involve this too), does that sound good ?

@kidonng

kidonng commented Nov 9, 2026 •

Copy link
Copy Markdown
Member

🫤 I am not sure if some incorrect errors are acceptable. To replicate the check accurately it should be possible to replicate the check request, which is just a few KBs of metadata:

Details
// https://github.githubassets.com/assets/packages/comment-box/api/file-upload.ts
async function getPolicy(file: File, repositoryId?: string, projectId?: string) {
  const formData = new FormData()
  const {name, size, type} = file
  if (repositoryId) formData.append('repository_id', repositoryId)
  if (projectId) {
    formData.append('upload_container_type', 'project')
    formData.append('upload_container_id', projectId)
  }
  formData.append('name', name)
  formData.append('size', size.toString())
  formData.append('content_type', type)

  const response = await verifiedFetch('/upload/policies/assets', {body: formData, method: 'POST'})

  return response
}

But I bet it could be all implemented locally, permission check and all that. I think it's safer if this looks like a warning instead of an error though, since it's not us blocking the upload. Anyway, if you want to implement it via local checks, be sure to include WebP, which is not mentioned by the docs but is supported:

// https://github.githubassets.com/assets/packages/one-copilot-composer/src/task/use-markdown-image-upload.ts
export const ACCEPTED_IMAGE_FILE_TYPES: FileType[] = ['image/png', 'image/jpeg', 'image/gif', 'image/webp']

@Mushir-Ali

Mushir-Ali commented Nov 9, 2026 •

Copy link
Copy Markdown
Author

@kidonng Thank you, i am going with the local policy check provided by the github. Also, rather than firing the second request, i should try to intercept the Github's own policy response, because 422 carries the exact message (example : "The video is too big... less than 10 MB"). Also i'll turn the toast from error to a warning style as you suggested, and also include webP. Is there an existing helper in the repo for patching fetch, or a preferred pattern for this?

@Mushir-Ali

Copy link
Copy Markdown
Author

@kidonng To intercept the GIthub's policy response, i need to wrap "window.fetch" for the whole page, since Refined-Github does not seem to have any helper for it. Is patching fetch globally, acceptable here, or would prefer a narrower approach ?

@kidonng

kidonng commented Nov 12, 2026

Copy link
Copy Markdown
Member

I didn't mention intercepting global fetch because that seems too high risk. I would wait for fregante to decide how this should proceed

@Mushir-Ali

Copy link
Copy Markdown
Author

@kidonng, understandable, for now, i'll hold off on the fetch approach. @fregante whenever you have a moment, happy to work whichever way you prefer.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Development

Successfully merging this pull request may close these issues.

Provide a better error than stock when a file is over 10mb (too large)

3 participants