# Upload file failing with request entity too large

**URL:** <https://community.forestadmin.com/t/upload-file-failing-with-request-entity-too-large/6311>\
**Category:** Help me!\
**Tags:** smart-action\
**Created:** [May 18, 2023, 6:21am UTC](https://community.forestadmin.com/t/upload-file-failing-with-request-entity-too-large/6311 "2023-05-18T06:21:48Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![khaled-faour](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/khaled-faour/32/6118_2.png) [@khaled-faour](https://community.forestadmin.com/u/khaled-faour)\
**Post date:** [May 18, 2023, 6:21am UTC](https://community.forestadmin.com/t/upload-file-failing-with-request-entity-too-large/6311/1 "2023-05-18T06:21:48Z")

</div>

## Feature(s) impacted

File upload through forest admin, logging into forest admin when placing `app.use(bodyParser.json({ limit: '50mb' })); app.use(bodyParser.urlencoded({ extended: true, limit: '50mb', parameterLimit: 500000 })); app.use(bodyParser.text({ limit: '50mb' })) `  
before creating the forest admin agent in NestJS

## Observed behavior

when the code is in this sequence, i am able to login to forest admin, however i cant upload a file greater than 1 MB.

```javascript
const app = await NestFactory.create(AppModule, new ExpressAdapter(express()));

  const agent = createAgent({
    authSecret: process.env.FOREST_AUTH_SECRET,
    envSecret: process.env.FOREST_ENV_SECRET,
    isProduction: process.env.NODE_ENV === 'production',
    typingsPath: './typings.ts',
    typingsMaxDepth: 5,
  })
    .addDataSource(createSqlDataSource(process.env.DATABASE_URL))
    .customizeCollection('Player', playerCollections)
    .customizeCollection(
      'PlayerUpcomingTurnamentMapping',
      playerUpcomingTurnamentMappingCollections,
    )
    .customizeCollection('PredefinedLogo', predefinedLogoCollections)
    .customizeCollection('Tournament', tournamentCollections)
    .customizeCollection('LeaguePageVariables', leaguePageVariablesCollections)
    .customizeCollection('League', leagueCollections)
    .mountOnNestJs(app);

  app.use(bodyParser.json({ limit: '50mb' }));
  app.use(bodyParser.urlencoded({ extended: true, limit: '50mb', parameterLimit: 500000 }));
  app.use(bodyParser.text({ limit: '50mb' }))

```

When the code is placed in this order

```javascript
const app = await NestFactory.create(AppModule, new ExpressAdapter(express()));

  app.use(bodyParser.json({ limit: '50mb' }));
  app.use(bodyParser.urlencoded({ extended: true, limit: '50mb', parameterLimit: 500000 }));
  app.use(bodyParser.text({ limit: '50mb' }))

  const agent = createAgent({
    authSecret: process.env.FOREST_AUTH_SECRET,
    envSecret: process.env.FOREST_ENV_SECRET,
    isProduction: process.env.NODE_ENV === 'production',
    typingsPath: './typings.ts',
    typingsMaxDepth: 5,
  })
    .addDataSource(createSqlDataSource(process.env.DATABASE_URL))
    .customizeCollection('Player', playerCollections)
    .customizeCollection(
      'PlayerUpcomingTurnamentMapping',
      playerUpcomingTurnamentMappingCollections,
    )
    .customizeCollection('PredefinedLogo', predefinedLogoCollections)
    .customizeCollection('Tournament', tournamentCollections)
    .customizeCollection('LeaguePageVariables', leaguePageVariablesCollections)
    .customizeCollection('League', leagueCollections)
    .mountOnNestJs(app);

```

I am not even able to login to my forest admin server.

## Expected behavior

When placing

```javascript
 app.use(bodyParser.json({ limit: '50mb' }));
  app.use(bodyParser.urlencoded({ extended: true, limit: '50mb', parameterLimit: 500000 }));
  app.use(bodyParser.text({ limit: '50mb' }))

```

before creating the forest admin agent, i expect to be able to login and to upload files greated than 1MB

## Failure Logs

```javascript
InternalServerError: stream is not readable
      at readStream (C:\Users\KMF\Documents\Poyesis\fantasy-tennis\fantasy-tennis-backoffice\node_modules\raw-body\index.js:185:17)
      at executor (C:\Users\KMF\Documents\Poyesis\fantasy-tennis\fantasy-tennis-backoffice\node_modules\raw-body\index.js:120:5)
      at new Promise (<anonymous>)
      at getRawBody (C:\Users\KMF\Documents\Poyesis\fantasy-tennis\fantasy-tennis-backoffice\node_modules\raw-body\index.js:119:10)
      at AsyncFunction.module.exports [as json] (C:\Users\KMF\Documents\Poyesis\fantasy-tennis\fantasy-tennis-backoffice\node_modules\co-body\lib\json.js:39:21)
      at parseBody (C:\Users\KMF\Documents\Poyesis\fantasy-tennis\fantasy-tennis-backoffice\node_modules\koa-bodyparser\index.js:99:26)
      at bodyParser (C:\Users\KMF\Documents\Poyesis\fantasy-tennis\fantasy-tennis-backoffice\node_modules\koa-bodyparser\index.js:80:25)
      at dispatch (C:\Users\KMF\Documents\Poyesis\fantasy-tennis\fantasy-tennis-backoffice\node_modules\koa-compose\index.js:42:32)
      at C:\Users\KMF\Documents\Poyesis\fantasy-tennis\fantasy-tennis-backoffice\node_modules\@koa\router\lib\router.js:425:16
      at dispatch (C:\Users\KMF\Documents\Poyesis\fantasy-tennis\fantasy-tennis-backoffice\node_modules\koa-compose\index.js:42:32)
      at cors (C:\Users\KMF\Documents\Poyesis\fantasy-tennis\fantasy-tennis-backoffice\node_modules\@koa\cors\index.js:108:22)
      at dispatch (C:\Users\KMF\Documents\Poyesis\fantasy-tennis\fantasy-tennis-backoffice\node_modules\koa-compose\index.js:42:32)
      at C:\Users\KMF\Documents\Poyesis\fantasy-tennis\fantasy-tennis-backoffice\node_modules\@koa\router\lib\router.js:425:16
      at dispatch (C:\Users\KMF\Documents\Poyesis\fantasy-tennis\fantasy-tennis-backoffice\node_modules\koa-compose\index.js:42:32)
      at C:\Users\KMF\Documents\Poyesis\fantasy-tennis\fantasy-tennis-backoffice\node_modules\koa-compose\index.js:34:12
      at dispatch (C:\Users\KMF\Documents\Poyesis\fantasy-tennis\fantasy-tennis-backoffice\node_modules\@koa\router\lib\router.js:430:31)

```

## Context

- Project name: Fantasy Tennis
- Team name: Poyesis
- Environment name: Production and Development
- Agent (forest package) name & version:  
`"@forestadmin/agent": "^1.8.3", "@forestadmin/datasource-sql": "^1.2.4",`
- Database type: Postgresql

---

<div class="post-metadata">

**Author:** ![arnaud](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/arnaud/32/32_2.png) [@arnaud](https://community.forestadmin.com/u/arnaud)\
**Post date:** [May 18, 2023, 9:08am UTC](https://community.forestadmin.com/t/upload-file-failing-with-request-entity-too-large/6311/2 "2023-05-18T09:08:49Z")

</div>

Hi @khaled-faour,

Is it a feature you’re trying to implement right know? or do you think it is a recent regression?  
Did you try those changes based on some official documentation you found?

Thanks for your help.

---

<div class="post-metadata">

**Author:** ![anon62739609](https://avatars.discourse-cdn.com/v4/letter/a/c2a13f/32.png) [@anon62739609](https://community.forestadmin.com/u/anon62739609)\
**Post date:** [May 23, 2023, 8:00am UTC](https://community.forestadmin.com/t/upload-file-failing-with-request-entity-too-large/6311/3 "2023-05-23T08:00:03Z")

</div>

If you have an nginx you will need to update the payload size too with `client_max_body_size`.  
You can take a look at [this link](https://docs.rackspace.com/support/how-to/limit-file-upload-size-in-nginx/) if that’s your case.
