I am looking to create an if statement that would allow me to check if a file that the user has attached to a piece of content via a media picker is of a specific file format. i.e. ".mp4"
If a user uploads a video, I can wrap the video html within an if statement that would check if there is a video file attached then show the video embed.
Thank you for your reply Jonathan, however when using that code I get the following error
CS1061: 'IPublishedContent' does not contain a definition for 'Media' and no accessible extension method 'Media' accepting a first argument of type 'IPublishedContent' could be found (are you missing a using directive or an assembly reference?)
Yeah just for the record the model builder is enabled. But even with the suggested code I am getting:
CS1061: 'object' does not contain a definition for 'UmbracoExtension' and no accessible extension method 'UmbracoExtension' accepting a first argument of type 'object' could be found (are you missing a using directive or an assembly reference?)
Would you mind providing your solution or marking the answer that helped you solving your problem as solution for others that are facing the same problem?
Getting the File Type/Format of a file
Hello,
I am looking to create an if statement that would allow me to check if a file that the user has attached to a piece of content via a media picker is of a specific file format. i.e. ".mp4"
If a user uploads a video, I can wrap the video html within an if statement that would check if there is a video file attached then show the video embed.
I hope that makes sense.
Hi Bry,
you can check for the build-in umbraco property "UmbracoExtension".
So it would look like this:
-Jonathan
Thank you for your reply Jonathan, however when using that code I get the following error
"Media" is an example. You'll have to replace "Media" with your own property alias.
Is your model builder enabled? If not, you will have to do it like this:
Yeah just for the record the model builder is enabled. But even with the suggested code I am getting:
Resolved!
Great to here you got it working!
Would you mind providing your solution or marking the answer that helped you solving your problem as solution for others that are facing the same problem?
Jonathan
You could do something like this
var file = Model.Value
@if (file.Value("umbracoExtension") == "mp4" ) { // do something }
Another non-Umbraco way is MimeMapping which does not rely on the file extension.
An example is
In .NET 4.5+ just use System.Web.MimeMapping.GetMimeMapping which can be found in
Namespace: System.Web
Assembly: System.Web.dll
https://referencesource.microsoft.com/#system.web/MimeMapping.cs
is working on a reply...