mynethome.de

13. Juni 2018 um 07:25 Uhr

Micronaut.io: Size Limit for FileUploads

Recently, I’ve been tinkering with Micronaut.io a new application framework which looks quite promising so far.
A good introduction is provided in the documentation, by the examples on GitHub and some nice articles on the web like „Getting Started with Micronaut“ by Jonas Havers.

I had to dig a little bit to find out some things when implementing a file upload. So here are some notes about it, maybe it help ssomeone else ;)

The basic documentation on file uploads provided by the main doc is a good starting point.

Then one might stuble quickly on a fairly well known exception like:

{"_links":{"self":{"href":"/upload","templated":false}},"message":"The received length [1049482] exceeds the maximum content length [1048576]"}

Not straight-forward to find is that the section „body annotations“ provides an answer on what the config setting to adjust this is. Also, it hints for the annotation @Size to provide a value per endpoint which is useful to set different limits in differnt contexts.

For an example how the config is done via an application.yml file can be found in the serverConfiguration paragraph of the documentation.

An important thing to note is when dealing with form based file uploads, you might use enctype="multipart/form-data" and thus need another attribute to set the upload limit. That would be micronaut.server.multipart.maxFileSize. Thus, I ended up with with the config:

micronaut:
    application:
        name: sample-application
    server:
        maxRequestSize: 100MB
        multipart:
          maxFileSize: 100MB

Also, a a final note for this post, let me remind you that as Micronaut is fairly young, it helps to keep an eye on the FAQ and Problems section. I had the problem regarding the startup time, for example, for which the solution is provided there. So easy to solve if you know what to do ;-)

Einen Kommentar schreiben


Gravatar unterstützt

mynethome.de wird erstellt mit WordPress
Beiträge (RSS) und Kommentare (RSS)

(c) 2005 - 2023 Markus Schlichting - Mastodon