Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Daniel Larsen 116 posts 381 karma points
    Apr 23, 2013 @ 00:30
    Daniel Larsen
    0

    How to display filesize of media selected in mediapicker

    Hi :-)

    How do I display the filesize of a media selected in mediapicker?

    Thanks. 

    Daniel :-)

     

     

  • Tom Fulton 2030 posts 4998 karma points c-trib
    Apr 23, 2013 @ 05:37
    Tom Fulton
    1

    You should be able to just get the "umbracoBytes" property (just like you would get the "umbracoFile" property), ie:

    <p>@yourMediaNode.umbracoBytes</p>
    <p>@yourMediaNode.GetPropertyValue("umbracoBytes")</p>

    -Tom 

  • Daniel Larsen 116 posts 381 karma points
    Apr 23, 2013 @ 10:28
    Daniel Larsen
    0

    Thank you, but it did not work.

    @foreach (var childPage in Model.Children.Where("Visible"))
    {
    foreach (var item in childPage.Descendants("FileItem").Where("Visible")) {
    var size = @item.MediaNode.GetPropertyValue("umbracoBytes");

    <p>@size</p>
    }

    This is my code, boiled down to the most essential. :-)

  • Tom Fulton 2030 posts 4998 karma points c-trib
    Apr 23, 2013 @ 18:19
    Tom Fulton
    0

    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 you're getting any error let us know 

    -Tom

  • Daniel Larsen 116 posts 381 karma points
    Apr 23, 2013 @ 18:37
    Daniel Larsen
    0

    Thank you, now there is no error, but it still doesn't display/output anything.

    Daniel

  • Tom Fulton 2030 posts 4998 karma points c-trib
    Apr 23, 2013 @ 18:40
    Tom Fulton
    0

    Are you able to pull other properties like the name or umbracoFIle?

    <p>@media.Name</p>
    <p>@media.GetPropertyValue("umbracoFile")</p>
    <p>@media.umbracoFile</p>

    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 

  • Daniel Larsen 116 posts 381 karma points
    Apr 23, 2013 @ 18:48
    Daniel Larsen
    0

    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

  • Tom Fulton 2030 posts 4998 karma points c-trib
    Apr 23, 2013 @ 18:51
    Tom Fulton
    100

    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

  • Daniel Larsen 116 posts 381 karma points
    Apr 23, 2013 @ 19:03
    Daniel Larsen
    0

    Thank you! :-D

    Just to be sure, what format is it displayed. Is it bytes?

    Daniel

  • Tom Fulton 2030 posts 4998 karma points c-trib
    Apr 23, 2013 @ 19:04
    Tom Fulton
    1

    Yup, bytes.  Glad that worked!

  • Clamond Ng 7 posts 74 karma points
    Sep 28, 2020 @ 07:27
    Clamond Ng
    1

    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");
    
  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies