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())
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
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.