SoFunction
Updated on 2025-04-25

The problem and solution of the SpringBoot project report error The field screenShot exceeds its maximum allowed size of 1048576 bytes.

Project Scenario

Tip: Project related background:

Project scenario:

  • Spring Boot-based file upload service uses MinIO as a distributed file storage system.
  • Users need to upload more than 1MB of files to the MinIO bucket.

Problem description

When the front-end passes the picture to the back-end, the back-end server reports an error:

Required request parameter 'examCard' for method parameter type String is not present:

File upload failed, and the system reported an error showing that the file size exceeded the limit. The specific error message indicates:

  • The currently uploaded file exceeds the limit of 1048576 bytes (1MB)
  • Errors have nothing to do with MinIO services and are limitations of Spring Boot application layer

Cause analysis

At first I thought the size of the image exceeded the size of the single uploaded file of minio, but later I found that it exceeded the default file upload limit of Spring Boot.

Spring Boot has strict file upload restrictions by default:

  1. defaultmax-file-size1MB (1048576 bytes)
  2. defaultmax-request-sizeAlso 1MB
  3. These restrictions are Spring Boot's security mechanism to prevent service resources from being exhausted due to large file uploads
  4. The MinIO service itself does not have this limitation, the problem lies in the Spring Boot application layer

Solution

existAdd the following configuration to the configuration file:

spring:
  servlet:
    multipart:
      max-file-size: 10MB    # Maximum size limit for single file      max-request-size: 100MB # Maximum size limit for the entire request

Configuration instructions:

  • max-file-size: Control the maximum size of a single uploaded file (example setting is 10MB)
  • max-request-size: Controls the maximum size of the entire request when uploading multiple files (example setting is 100MB)

These values ​​can be adjusted according to actual business requirements

After modification, you need to restart the application and take effect

Notice:

The production environment should set these values ​​reasonably according to actual hardware resources and business needs to avoid the risk of memory overflow caused by excessive settings.

Summarize

The above is personal experience. I hope you can give you a reference and I hope you can support me more.