Skip to content

[Feature Request] Configurable Body Parser Limits for Large JSON Payloads #516

@AvinashDalvi89

Description

@AvinashDalvi89

Summary

Currently, Motia's Express server uses the default body parser limits (~100kb), which prevents uploading larger base64-encoded images through JSON API endpoints. This limitation affects use cases that require processing larger files through JSON APIs.

Problem Description

When attempting to upload base64-encoded images larger than ~100kb through a JSON API endpoint, the server returns:

PayloadTooLargeError: request entity too large
    at readStream (/path/to/node_modules/raw-body/index.js:163:17)
    at getRawBody (/path/to/node_modules/raw-body/index.js:116:12)
    at read (/path/to/node_modules/body-parser/lib/read.js:79:3)
    at jsonParser (/path/to/node_modules/body-parser/lib/types/json.js:138:5)

Use Case

  • Image Processing API: Uploading base64-encoded images for processing (resize, optimization, etc.)
  • Document Processing: Handling large JSON payloads with embedded file data
  • Data Import APIs: Processing large datasets through JSON endpoints

Current Workaround

Currently limited to very small images (< 100kb base64-encoded) for testing.

Proposed Solution

Add configuration options to control Express body parser limits, either through:

Option 1: Configuration File

// motia.config.js or similar
module.exports = {
  server: {
    bodyParser: {
      json: { limit: '50mb' },
      urlencoded: { limit: '50mb', extended: true }
    }
  }
}

Option 2: Environment Variables

MOTIA_BODY_PARSER_JSON_LIMIT=50mb
MOTIA_BODY_PARSER_URLENCODED_LIMIT=50mb

Option 3: CLI Options

motia dev --body-limit 50mb

Technical Details

  • Framework: Motia (using Express.js internally)
  • Current Default: ~100kb (Express default)
  • Desired Limit: Configurable (e.g., 50mb for image processing)
  • Body Parser: Uses body-parser package internally

Example API Endpoint

// steps/upload-image.step.ts
export const config: ApiRouteConfig = {
  method: 'POST',
  path: '/upload-image',
  bodySchema: z.object({
    filename: z.string(),
    data: z.string() // base64 encoded image - can be large
  })
}

Impact

  • High: Blocks image processing and file upload use cases
  • Workaround Complexity: Requires splitting large payloads or alternative upload methods
  • User Experience: Prevents straightforward JSON API design for file handling

Additional Context

  • Base64 encoding increases file size by ~33%
  • A 1MB image becomes ~1.3MB when base64-encoded
  • Common image sizes (2-5MB) easily exceed current limits
  • This is a common pattern in modern web APIs

Environment

  • Motia Version: 0.5.2-beta.102-976525
  • Node.js: 18.19.0
  • Platform: macOS (darwin)

Related

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions