I am trying to upload file using strapi upload api. I get 413 error

Strapi : 3.6.8

Using postman I am able to upload image as mentioned in the docs :slight_smile: Upload - Strapi Developer Documentation

But I am not unable to upload it from nodejs code. Here is my nodejs code :slight_smile:


Found something online, hope it helps.
The 413 status code indicates that the request was larger than the server is able to handle , either due to physical constraints or to settings. Usually, this occurs when a file is sent using the POST method from a form, and the file is larger than the maximum size allowed in the server settings.

Any idea how to solve this?

were you able to solve this?

Hi Yes, can you try :

headers: { 
                          'Authorization': 'Bearer '+token,
                          ...data.getHeaders()
                        },

Same here. Any evolution?

My strapi version 4.3.8

Iā€™m trying to upload a PDF file with 5MB. Before to know what was the problem, i thought the problem was CORS. But when i upload a PDF with 800kb, it works.

I added on my middlewares.js file the follow code:

// ...
{
    name: "strapi::body",
    config: {
      jsonLimit: "20mb",
      formLimit: "20mb",
      textLimit: "20mb",
      formidable: {
        maxFileSize: 20 * 1024 * 1024,
      },
    },
  },
//...

My server is configured with
Nginx Proxy + PM2

2 Likes

UPDATE

The error was not in Strapi, but in my NGINX web server as proxy reverse mode.

I increased the Max Body Size from 1mb to 10mb and the problem was solved.

nginx.conf

http {
    # ...
    client_max_body_size 10M;
    # ...
}
5 Likes

This was the answer for me: How to Limit File Upload Size in Nginx

Please , Can you specify where to create nginx.conf

On my server is located on path /etc/nginx/nginx.conf

1 Like

If you are using Nginx, follow these steps:

Open the configuration file for your Strapi server:

sudo nano /etc/nginx/sites-available/your_strapi_server_conf

Inside the configuration, set the following:

server {
    # others settings...

    client_max_body_size 10M;

    # others settings...
}

After making these changes, restart the server:

sudo service nginx restart

And its all :slight_smile:

1 Like

Thanks for your help.