413 Request Entity Too Large when sending image data

apache, html, nginx, perl

Solution

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/;
        }
    }
}

Problem

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?

Original source

Related problems