Is MediaNode the alias of your Media Picker? If so you'll need to use GetMedia or MediaById to get a reference to the media node first. Not used this Razor in a while, but IIRC, it's:
var media = Library.MediaById(@item.MediaNode); var size = media.GetPropertyValue("umbracoBytes");
If so, maybe go to the media item in the media section and see if it has a value entered for "size"? It should be computed automatically when you upload it. If this is a custom media type you'll need to add the umbracoBytes property and re-save (or re-upload?) your media to get that value populated - or we can calculate it on the fly with some additional code if that's what you prefer.
If you wanted to know the file size and file extension in V8.
var media = Model.Value<IPublishedContent>("mediaFile");
var mediaSize = media.Value("UmbracoBytes");
var mediaExtension = media.Value("UmbracoExtension");
How to display filesize of media selected in mediapicker
Hi :-)
How do I display the filesize of a media selected in mediapicker?
Thanks.
Daniel :-)
You should be able to just get the "umbracoBytes" property (just like you would get the "umbracoFile" property), ie:
-Tom
Thank you, but it did not work.
This is my code, boiled down to the most essential. :-)
Is MediaNode the alias of your Media Picker? If so you'll need to use GetMedia or MediaById to get a reference to the media node first. Not used this Razor in a while, but IIRC, it's:
If you're getting any error let us know
-Tom
Thank you, now there is no error, but it still doesn't display/output anything.
Daniel
Are you able to pull other properties like the name or umbracoFIle?
If so, maybe go to the media item in the media section and see if it has a value entered for "size"? It should be computed automatically when you upload it. If this is a custom media type you'll need to add the umbracoBytes property and re-save (or re-upload?) your media to get that value populated - or we can calculate it on the fly with some additional code if that's what you prefer.
-Tom
I can see I made a mistake in the very first post. It is not the Media Picker I use. It is the Upload type. Sorry for the mistake.
But still no luck. I tried republiching the page and re-uploaded the files.
Daniel
Ah, makes sense. The upload type by itself doesn't store any size information, so you'll need to calculate it yourself.
If you have uComponents installed, they have a nice helper method you can use to do this - see this thread.
-Tom
Thank you! :-D
Just to be sure, what format is it displayed. Is it bytes?
Daniel
Yup, bytes. Glad that worked!
If you wanted to know the file size and file extension in V8.
is working on a reply...