Unable to post content to strapi which is more than 1 MB in size

System Information
  • Strapi Version: 3.4.6
  • Operating System: Microsoft windows server 2019 standard
  • Database: Mongo DB v4.4.0
  • Node Version: v14.15.1
  • NPM Version: 6.14.8
  • Yarn Version:

Hello Strapi Community,

We are encountering an issue when posting large content to Strapi to persist it in a specific collection of Mongo DB. It is observed that whenever we post any data via http that is more than 1 MB, we get a error response stating " Bad request" back from Strapi.

Is there any specific file which we need to update to allow this? In our use-case, we may have a content around 5 MB as well which needs to be posted via http call to strapi.

Please advice.

1 Like

Take a look at the parser Middleware, it’s default limit is set to 1mb, but you can extend it:

./config/middleware.js:

module.exports = {
  // ...
  settings: {
    parser: {
      // ...
      formLimit: '10mb', // modify here limit of the form body
      jsonLimit: '10mb', // modify here limit of the JSON body
      formidable: {
        maxFileSize: 100 * 1024 * 1024, // multipart data, modify here limit of uploaded file size
      },
    },
  },
};

Hi SunnySon,

Thanks for your reply.

Unfortunately this setting does not seem to come into effect. By default there was no ‘middleware.js’ file in the ./config directory. Hence a new file was created with the required name and the content you have shared above. Post which Strapi was restarted as well.

When we try to POST a payload which was 4.7MB in size, we got a response as “documentations/:Payload Too Large” , wherein the ‘documentations’ is the collection name.

How do we confirm if this config file settings are into effect ? Is there any other settings to be enabled?

Please advice.

Regards,
Prashanth Kamath

Can you also try to add textLimit:

module.exports = {
  // ...
  settings: {
    parser: {
      // ...
      formLimit: '10mb', // modify here limit of the form body
      jsonLimit: '10mb', // modify here limit of the JSON body
      textLimit: '10mb', // modify here limit of the text body
      formidable: {
        maxFileSize: 100 * 1024 * 1024, // multipart data, modify here limit of uploaded file size
      },
    },
  },
};

Parser middleware uses the koa-body module, so all these options from parser are passed to it. You can view all available options here:

koa-body also uses formidable for form-data content(file uploads), you can view all it’s available options here:

Hi @sunnyson , this seems to work now. Thanks a lot for your help

I added this middleware.js, built again and restarted server. This works on my dev environment, but, on production, I cannot upload files larger than 1 MB. I get “413 Request Entity Too Large”
strapi v3.6.6

1 Like

https://docs.rackspace.com/support/how-to/limit-file-upload-size-in-nginx/
My issue was because of Nginx. Resolved by increasing upload limit in nginx.

5 Likes

@sunnyson I am facing issues while uploading video files in Strapi. It keeps on giving error file size too big. The videos are around 18 mb or more. Can we increase the limit for uploading video as well?

I’ve modified both middleware.js and my nginx configuration and I’m still having problems. I’m not sure what I’m doing wrong.

The Koa body parser settings are currently not being passed for GraphQL requests.

Issue: Graphql request - 413 Payload too large · Issue #11558 · strapi/strapi · GitHub

1 Like

I’m wondering if the technical solutions presented here are still applicable for Version 4 of Strapi.
I was running Strapi v4 locally, in development mode quickstart (so, SQLite, local storage).
I attempted to use the Media Library tool to upload a 370Mb MP4 video file, and got the 413 error.

What middleware.js (if that) changes are needed in V4?
When it comes to stuff deployed on an integration and/or production server, I know I will need to configure nginx too.

I use Strapi v4 and I need to extend the json limit to 5mb. The ./config/middleware.js now exports an array and I don’t know how to modify the settings of the parser. I greatly appreciate if you have any advice. Thanks

Has anyone managed to find how to change these limits for Strapi v4?

EDIT:

Found the answer!

For v4 you need to change your /config/middlewares.js to look something like this:

module.exports = [
  "strapi::errors",
  "strapi::security",
  "strapi::cors",
  "strapi::poweredBy",
  "strapi::logger",
  "strapi::query",
  {
    name: "strapi::body",
    config: {
      formLimit: "256mb", // modify form body
      jsonLimit: "256mb", // modify JSON body
      textLimit: "256mb", // modify text body
      formidable: {
        maxFileSize: 200 * 1024 * 1024, // multipart data, modify here limit of uploaded file size
      },
    },
  },
  "strapi::favicon",
  "strapi::public",
  "global::globalTest",
  "global::globalBlah",
];
8 Likes

This worked great!

Does anyone know if it’s possible to do this for specific endpoints of fields? Or can it only be done globally with middleware.

For example, I only want to increase the allowed size for a specific field when it is edited in the admin console. But I’d like to keep the default restrictions on content added by users with REST requests.

1 Like

Apparently this was fixed only very recently: fix: ApolloServer middleware CORS issue

I am on 3.6.9 where this issue still exists in strapi-plugin-graphql

I tried changing config as above, still i am facing same issue, can someone pls guide me

@arshi-mustafa786

plugins.js

module.exports = ({ env }) => ({
  ...,
  upload: {
    config: {
      providerOptions: {
        sizeLimit: 5 * 1024 * 1024, // 5 MB
        localServer: {},
      },
    },
  },
 ...
});

@arshi-mustafa786 did this work for you?

Hi, i have the same problem on my Strapi v4.4.1.
Images > 1mb will not uploaded and return “An error occurred while uploading the file.”.
I have changed middlewares.js with this config but the problem persist.
Is there an alternative solution or a suggestion?

I have found the solution for me.
I have changed the max file size on my reverse proxy.

1 Like