Uploading a 1MB PDF I'm getting « upload is too big, maximum is 4MB »

I’m getting the « upload is too big, maximum size is 4MB » error message when uploading less than 4MB PDF files.
Here are my tests:

  • a PDF of 68KB goes OK as expected.
  • a JPG of 2.3M does OK as expected.
  • a pdf (2.3 MB) of 2.3M triggers the error !
  • a JPG of 3.6MB goes OK as expected.

Strangely the upload goes successfully on meta.discourse.org, maybe you changed some settings.

I have no modified settings containing max.

I’m using version 2.9.0.beta9 4af080d20b, on a self-hosted instance at https://discuss.afpy.org.

No issue with this file on my forums on which I didn’t change the file size limit.

1 Like

Giving it a run-through on my test site (4b561277a9) with no changes to any max settings or file limits and it uploads fine for me if I add pdf to authorized extensions, and gives the correct error message of ‘Sorry, the file you are trying to upload is not authorised’ when it’s reset to default.

Is there something else I could try to see if I can replicate?

No, as that file size is under the default nginx size limit. However that is a good clue.

The site @Julien_Palard self-hosts has a custom reverse-proxy between Discourse and the browser, so that error is probably coming from a misconfigured reverse proxy.

5 Likes

Do you have a reverse proxy in front of your Discourse? How did you install?

I’m using nginx, my configuration goes like:

so my nginx config is:

      server
      {
          listen [::]:80; listen 80;
          server_name {{ discourse_domain }};
          access_log /var/log/nginx/{{ discourse_domain }}-access.log;
          error_log /var/log/nginx/{{ discourse_domain }}-error.log;
          return 301 https://$host$request_uri;
      }
      server
      {
          listen [::]:443 ssl; listen 443 ssl;
          server_name {{ discourse_domain }};
          access_log /var/log/nginx/{{ discourse_domain }}-access.log;
          error_log /var/log/nginx/{{ discourse_domain }}-error.log;
          include snippets/letsencrypt-{{ discourse_domain }}.conf;
          location / {
              proxy_pass http://unix:/var/discourse/shared/standalone/nginx.http.sock:;
              proxy_set_header Host $http_host;
              proxy_http_version 1.1;
              proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
              proxy_set_header X-Forwarded-Proto https;
              proxy_set_header X-Real-IP $remote_addr;
          }
      }

It’s an nginx 1.18.0-6.1+deb11u2 from Debian bullseye.

I’m getting a 413 Request Entity Too Large from nginx so clearly I have to dig further to understand why a “big” image is OK but a “not so big” PDF is not…

The 3.0MB JPG have a Content-Length of  557215 so 0.5MB surprisingly!
The 2.3MB PDF have a Content-Length of 2460137 so 2.3MB unsurprisingly.

Does Discourse rescale the jpg before uploading it?

On my passing JPEGs I see the image width and height as different after uploading them to Discourse (Tried with https://apod.nasa.gov/apod/image/2209/DSCF4968_PS_Lioce.jpg, it’s a 5703x3892, 3.6MB picture, but once uploaded it’s a 1920×1310 of 153 KB one.

1 Like

The nginx default for client_max_body_size is 1MB, client-side rescaled jpegs are all under 1MB, everything become clear.

I fixed my nginx config: Set client_max_body_size to 4m to match Discourse configuration. · AFPy/infra@861af29 · GitHub

And it now works. You were right: it was my reverse proxy.

Thank you all :heart: and sorry for the noise!

4 Likes

I don’t want to wrongly add the tag unsupported-install, but I guess this topic should have had it from the start right?

Well, there are topics for explaining how to configure a reverse proxy, so this is something that we typically help with.

1 Like

Angry Season 4 GIF by The Office

YES! And we even have a blog post about this super awesome feature

7 Likes

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.