Search code examples
scalaplayframeworkplayframework-2.4hocon

How to read size in bytes syntax in Play configuration (HOCON)?


The Play documentation claims it supports declaring sizes in quantity prefixes (MB, MiB, GB, etc.) It doesn't however state how I'm supposed to read such values in code.

I have the following configuration value:

discavo.upload.image.maxSize = 2 MiB

and I tried loading it as

current.configuration.getInt("discavo.upload.image.maxSize").get

but got the following error:

Configuration error[conf/application.conf: 129: discavo.upload.image.maxSize has type STRING rather than NUMBER]

Solution

  • I found that you should use getBytes instead of getInt, which returns an Option[Long]:

    current.configuration.getBytes("discavo.upload.image.maxSize").get.toInt