XF 2.2 Uploading image attachments via URL (HTTP) leads to "Uploaded file is too large"


Uploading images from another server via HTTP often fails with "Oops - Uploaded file is too large", even if the file being fetched doesn't exceed maximum file size.

How to replicate?
  1. Set a maximum file size of e.g. 2000kB in admin panel under Options -> Attachments -> Maximum attachment file size
  2. Open a website containing an image you want to attach to the post (not to insert as img tag), e.g. https://i.redd.it/q73rqtpz0vy41.jpg (which is around 200kB)
  3. Right click image and select "Copy image" (to copy the image data, not the URL)
  4. Switch to XenForo text editor (posting, private communication, whatever)
  5. Either right click -> Paste or click into text area and hit Ctrl+V
The image is then loaded from the URL, displayed as progress bar. At 100% the message "Oops - Uploaded file is too large" appears, although the file (200kB) is much smaller than the maximum file size (2000kB).

What did I test?

I looked into the source code at src/XF/Http/Upload.php in line 560 which is the line throwing the error. I replaced the XF phrase with 'fSize: ' . $this->fileSize . ' - maxFSize: ' . $this->maxFileSize which revealed that the 200kB file "expanded" to over 3MB after upload, throwing the "too large" error. I repeated the test with various other image files with the same results, the file sizes somehow were always at least ten times bigger than the original file I tried to fetch.

  • PHP 7.4.16
  • XenForo 2.2.5
  • No add-ons
Any ideas if this is a bug, a known behavior of maybe PHP or something else I'm missing?


Forgot to mention that uploading from the client works without issues. If the image is too large (dimensions) it is resized automatically regarding the numbers in attachments settings. This only happens when uploading from a URL via HTTP.
Last edited:
Thanks for the replies so far @mcatze @Max Taxable!

maxImageResizePixelCount is already set to 30,000,000. The image mentioned in the posting is just 1,915 x 1,069 = 2,047,135 pixels. I forgot to mention that there's absolutely no issues with uploading from the client at whatever file size (auto resize hits in then), only uploading from a URL throws in this case.
Thanks for taking the time @Brogan!

The image size typically increases as part of the upload process.
Could you please explain this a bit or maybe you have a link where I can read about it why it typically increases? AFAIK the file is transferred via HTTP into memory as is. Since it is a JPG already even if the web server would send it gzipped it wouldn't become that big (200kB <-> >3MB). Although it is no GZ issue, after downloading, the file is 200kB still when saved to disk. One thing coming to my mind possibly explaining the huge file size is that it is somehow expanded from JPG into bitmap before it gets evaluated by XenForo?

What do have set for this:
2,048 x 2,048, while the file already is 1,915 x 1,069, so there should be no resize happening.
To clarify, the process you're doing is not really uploading from a URL. You may not be uploading the same file/content that you think you're uploading. There's a very good chance that what you're uploading may be, for example, a PNG. If the original image was a JPG, it's very possible that the new representation is quite a bit larger (a PNG version of a real life photo will tend to be a fair bit larger than a JPG). Essentially, it's possible the data is being re-encoded via the clipboard.

I just tried it with the example URL you provided and indeed, I can see that it has come across as a PNG and is now 2.4 MB.

As we simply take the image that the browser has provided, there isn't really anything that would be changed here.
Top Bottom