0

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]
Zoltán
  • 21,321
  • 14
  • 93
  • 134

2 Answers2

1

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

current.configuration.getBytes("discavo.upload.image.maxSize").get.toInt
Zoltán
  • 21,321
  • 14
  • 93
  • 134
0

in the conf, just write as following:

discavo.upload.image.maxSize = 2

instead of your code:

discavo.upload.image.maxSize = 2 MiB

the reason is that when you get the "discavo.upload.image.maxSize", you get '2 MiB' including number '2' and its unit 'MiB' that the method 'toInt' can convert it to a number.

Good luck with you

Jerry
  • 492
  • 4
  • 8
  • 1
    I'm not expecting to get `2`, but `2097152`, i.e. `2^20`, which the unit correctly represents. – Zoltán Jan 29 '16 at 15:48