I am on Umbraco versoin 7.5.9.
I see from intellisense in Visual Studio 2017 that UmbracoContext.Current.MediaCache has these properties
GetAtRoot, GetById, GetByxPath, GetHashCode, GetSingleByXPath
I do not see one for "Name".
Does anyone know how to query the UmbracoContext.Current.MediaCache by name?
You'll see that methods like GetByXPath and GetSingleByXPath aren't implemented for Media,
(this is because Media content isn't stored in an XML file format in the same way that content is (otherwise you could have used either of those methods to create an XPath search for an element with nodeName attribute equal to your search.
The Media information is stored in the database, but there is an Examine Search layer over the top for speed.
which has a GetMediaByXPath and GetMediaByName, but these will make a request to the db
what might be quicker is an Examine query of the media section?
So it depends a little on what you are trying to achieve? eg do you need to find a media item by name? could it be 'picked' or is it Search Media functionality...
Marc:
Since all Umbraco Media is stored on the file system, here is what I did.
I uploaded the Media (PDF document) to the production media folder.
When I had the user do this, it created a unique "id". Next, I combined some Javascript, Angular and a REST service Controller to retrieve the data and return it back as a JSON object using the MediaCache.GetById().
Its straight forward once you know this id.
So for each env (tst, stg, prd), I change the id value programmatically and I'm good to go.
Query UmbracoContext.Current.MediaCache by Name
Hello:
I am on Umbraco versoin 7.5.9. I see from intellisense in Visual Studio 2017 that UmbracoContext.Current.MediaCache has these properties GetAtRoot, GetById, GetByxPath, GetHashCode, GetSingleByXPath
I do not see one for "Name".
Does anyone know how to query the UmbracoContext.Current.MediaCache by name?
Thanks
BTD
Hi Tom
If you look at the implementation of the MediaCache here:
https://github.com/umbraco/Umbraco-CMS/blob/1bb593d264a085f94a3ce3bd710392b350561430/src/Umbraco.Web/PublishedCache/XmlPublishedCache/PublishedMediaCache.cs
You'll see that methods like GetByXPath and GetSingleByXPath aren't implemented for Media,
(this is because Media content isn't stored in an XML file format in the same way that content is (otherwise you could have used either of those methods to create an XPath search for an element with nodeName attribute equal to your search.
The Media information is stored in the database, but there is an Examine Search layer over the top for speed.
There is a legacy approach called uQuery: https://github.com/umbraco/Umbraco-CMS/blob/1bb593d264a085f94a3ce3bd710392b350561430/src/Umbraco.Web/umbraco.presentation/umbraco/uQuery/uQuery-Media.cs
which has a GetMediaByXPath and GetMediaByName, but these will make a request to the db
what might be quicker is an Examine query of the media section?
So it depends a little on what you are trying to achieve? eg do you need to find a media item by name? could it be 'picked' or is it Search Media functionality...
sorry to be a bit vague!
Marc: Since all Umbraco Media is stored on the file system, here is what I did. I uploaded the Media (PDF document) to the production media folder. When I had the user do this, it created a unique "id". Next, I combined some Javascript, Angular and a REST service Controller to retrieve the data and return it back as a JSON object using the MediaCache.GetById().
Its straight forward once you know this id. So for each env (tst, stg, prd), I change the id value programmatically and I'm good to go.
Thanks for pitching it.
BTD
is working on a reply...