Bytes is a drop-in replacement for Umbraco's "Label (bigint)" Data Type.
When you've uploaded an image to the Media section, have you wondered why the "Size" field displays such a long number?
Of course, it's the filesize of the image - in bytes. But how many kilobytes or megabytes is that?
The Bytes property-editor will make the filesize value human readable.
In your new Data Type, selected the "[Contentment] Bytes" option. You will see the following configuration fields.
The first field is Kilobytes?, this lets you define how many bytes are in a kilobyte - either 1000
or 1024
, (the default is 1024
).
Fun fact: In decimal, there are 1000 bytes in a kilobyte, whereas in binary, there are 1024 bytes. This is also known as a kibibyte.
The second field is Decimal places, used to set how many numbers are displayed after the decimal place. The default is 2
.
Next step is to add the Data Type to your Media Type (or Document Type, depending on how you want to use it).
The intended purpose for Bytes was to replace the "Size" property on the "File" or "Image" media-types, like so...
Once you have added the configured Data Type to your Media Type, the bytes will be displayed.
This property-editor is a read-only label.
The value for Bytes is a long
(i.e. Int64
). To use this in your view templates, here are some examples.
Assuming that are using this as the "Size" property on the "Image" Media Type, then...
Using Umbraco's Models Builder...
@Model.UmbracoBytes
Without ModelsBuilder...
Weakly-typed...
@Model.Value("umbracoBytes")
Strongly-typed...
@(Model.Value<long>("umbracoBytes"))
If you would like a .NET library to help byte size representation in code easier, check out ByteSize by Omar Khudeira.
Here are some more opinions on the matter...