I'm currently working on a webshop for a client. I'm going to replicate products, categories etc. to the website once every day. My challenge is as follows:
I'm planning on connecting the images to each product, by letting the client upload all the images to a specified folder in Umbraco (via. Media multiupload), and then merging the product id with ".jpg" ie. "010101.jpg" to create the image name when I need to show the image in the shop. But my problem is, that I dont know:
1) The id of the media item in Umbraco 2) The path of the media item in Umbraco
Therefore I cannot merge the full path to the image ("/media/145/010101.jpg").
I would greatly appreciate any takes on solving my challenge :-)
You could try using Hendy's helper methods (http://blog.hendyracher.co.uk/umbraco-helper-class/) and use the GetMediaFromXpath method to pull back media items based on the name. Not 100% sure on the XPath, but shouldn't be too difficuilt.
I'm not sure if this is true of Hendys helper methods, but I know Media calls are quite expensive in terms of DB calls, so if this is a problem you could do a direct DB query.
Alternativley, just ask if you are having any specific problems, I know a little about the DB, but the main thing to bare in mind is that everything is a node, so everything (content wise) holds an entry in the umbracoNode table.
If you're querying the database directly (and use paramterized queries) then that's just fine. If you're doing it through the api, in versions lower than 4.5, you will experience a serious performance penalty on each pageload. Also, if you're on the pre-4.5 version, check out my "cultiv media cache" package, that will save you many database calls in the frontend. Media caching is built in in 4.5 though.
I'm querying the database directly - and furthermore I'm doing it when the data is replicated. That way, when I need to render the presentation frontend, I already know the image paths.
But thanks for your information - It's nice to have peops watching your back :-)
Media path challenge
Hi everyone,
I'm hoping for some help here.
I'm currently working on a webshop for a client. I'm going to replicate products, categories etc. to the website once every day. My challenge is as follows:
I'm planning on connecting the images to each product, by letting the client upload all the images to a specified folder in Umbraco (via. Media multiupload), and then merging the product id with ".jpg" ie. "010101.jpg" to create the image name when I need to show the image in the shop. But my problem is, that I dont know:
1) The id of the media item in Umbraco
2) The path of the media item in Umbraco
Therefore I cannot merge the full path to the image ("/media/145/010101.jpg").
I would greatly appreciate any takes on solving my challenge :-)
Hi Martin,
You could try using Hendy's helper methods (http://blog.hendyracher.co.uk/umbraco-helper-class/) and use the GetMediaFromXpath method to pull back media items based on the name. Not 100% sure on the XPath, but shouldn't be too difficuilt.
I'm not sure if this is true of Hendys helper methods, but I know Media calls are quite expensive in terms of DB calls, so if this is a problem you could do a direct DB query.
Matt
Hi Matt,
Thanks a bunch for your suggestions.
I was onto a direct DB query earlier, but I've unsuccessfully searched for the schema of the Media DB. Can you point me in the right direction?
Hi Martin,
There is now definitive place, but you could try the following:
http://blog.hendyracher.co.uk/umbraco-database-part-2/
http://www.farmcode.org/post/2010/06/15/Umbraco-41-Database-Structure.aspx
Alternativley, just ask if you are having any specific problems, I know a little about the DB, but the main thing to bare in mind is that everything is a node, so everything (content wise) holds an entry in the umbracoNode table.
Matt
Hi Matt,
I ended up going the DB way, and it works like a charm.
Thanks for your help
If you're querying the database directly (and use paramterized queries) then that's just fine. If you're doing it through the api, in versions lower than 4.5, you will experience a serious performance penalty on each pageload. Also, if you're on the pre-4.5 version, check out my "cultiv media cache" package, that will save you many database calls in the frontend. Media caching is built in in 4.5 though.
I'm querying the database directly - and furthermore I'm doing it when the data is replicated. That way, when I need to render the presentation frontend, I already know the image paths.
But thanks for your information - It's nice to have peops watching your back :-)
is working on a reply...