Don't miss out Virtual Happy Hour this Friday (April 26).

Try our conversational search powered by Generative AI!

Blob size

Vote:
 

Hi

Is there a clever way get the size of a blob, ie. is it stored as metadata somewhere?

The below code works, but it seems excessive to open a stream each time.

public static long GetSizeInBytes(this MediaData instance)
{
    using (var stream = instance.BinaryData.OpenRead())
    {
        return stream.Length;
    }
}
#112765
Nov 05, 2014 11:19
Vote:
 

If you are using the standard FileBlobProvider, you can do something like this:

            var path = (myMediaData.BinaryData as FileBlob).FilePath;
            var length =  new FileInfo(path).Length;

which should be a less costly operation.

Optionally, you could create a "Size" property on the mediadata which is populated when the data is published


#112796
Edited, Nov 05, 2014 15:41
Vote:
 

Thanks, this works nicely.

The Size-property is probably the more correct approach, but then I'll have to re-publish 6GB worth of existing blobs. Alternatively use a fallback to FileInfo if size is zero and let it evolve over time as things are published.

#112825
Nov 06, 2014 0:45
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.