2

A part of my site takes an image from an HTML5 canvas using the method

 .toDataURL()

and then sends the raw data as part of a POST message to my server, with AJAX. On the server side, I have a cgi script expecting the long data string. I am consistently getting this error:

 413 (Request Entity Too Large) 

I'm using the perl CGI library, and I do not have

 $CGI::POST_MAX 

set, or

  $CGI::DISABLE_UPLOADS

set. Is this due to restrictions that are set in the server? I am using apache, and nginx as a proxy server. My worry is that I won't be able to get around this issue, since I'm writing my site to be installed on a bluehost server. Basically I have two questions: 1. is there a way to use an html5 canvas method to create a file-upload type post request to the server? 2. Is there any way around this 413 Error that doesn't involve messing with Apache/Nginx (or some other server) configurations?

pepper
  • 2,097
  • 5
  • 23
  • 29
  • Start by determining if it's your script or the server generating the error. – ikegami Apr 19 '13 at 03:28
  • 1
    If you don't have `$CGI::POST_MAX` set, then the error is either from Apache or Nginx. How large is the body? If it's within a few megabytes I would email the provider and ask them to set the limit to something reasonable. – chansen Apr 19 '13 at 05:35
  • And, since you have two servers, figure out which server it is that is sending the rror. Check the error logs. Also, please post your javascript POST code. – Dondi Michael Stroma Apr 19 '13 at 07:15

2 Answers2

3

If you’re getting 413 Request Entity Too Large errors trying to upload, you need to increase the size limit in nginx.conf or any other configuration file . Add client_max_body_size xxM inside the server section, where xx is the size (in megabytes) that you want to allow.

http {
    include       mime.types;
    default_type  application/octet-stream;
    sendfile        on;
    keepalive_timeout  65;

    server {
        client_max_body_size 20M;
        listen       80;
        server_name  localhost;

        # Main location
        location / {
            proxy_pass         http://127.0.0.1:8000/;
        }
    }
}
ajtrichards
  • 29,723
  • 13
  • 94
  • 101
2

This error is caused by a URL that is too long.

While there is no official limit to the length of the URL, in practice browsers and servers have limitations.

The maximum safe length for browsers is about 2000 characters. That was the limit for older versions of Internet Explorer. I think recent versions of IE allow about 4000, but Chrome is limited to about 2000, even though Google generates URLs longer than that.

The maximum length for servers varies by server.

So, if your data exceeds that, you probably need to come up with another way of sending it, instead of converting it to a URL string.

Community
  • 1
  • 1