New Module - Virtual Media

Topics: Announcements, Writing modules
Jun 25, 2011 at 12:04 AM
Edited Jun 25, 2011 at 12:12 AM

Hey Everyone!

Just submitted my first module to the gallery! 

Allows mapping of virtual paths to physical paths for media files for semantic URL's and SEO purposes. Existing and new media files that are added to content items after the install of this module should automagically reference the new virtual location.  Existing URL's for content parts like ImageGalleries and Body areas should also automatically adjust.

For instance you can now have a ~/Images/ Folder map to ~/Media/Default/MyImages/, or ~/Pics/ to ~/Default/Media/ImageGalleries/MyPics/ . You can set any number of virtual path maps as you'd like. 

Does not require Full Trust (You may have to specify additional MIME Types as necessary in the MimeTypes.txt file if you are not running Full Trust).


Special thanks to Pete Hurst for his assistance :)

 

One thing to note: There's a hack in place as I couldnt find a reliable way around what I wanted to do without it. It uses a text file for data persistence right now (it's updated automatically when saving the media settings) for matching routes in the IRouteConstraint

If someone wants to take a look at see if they can figure out how to resolve the transaction scope errors and crashes that would be awesome. (the code is commented out in the Helper class)

Jun 30, 2011 at 4:07 AM

can this map individual files as well, or just folders? thanks!

 

Jun 30, 2011 at 4:14 AM
Edited Jun 30, 2011 at 4:16 AM

Yes (just tested) it works for individual files too. Although it could get a little crazy to manage if you have a bunch of routes this way so I would suggest the folder approach and name the images however you want. in the physical location.

 

You could even do a map for something like ~/media/default/images/coolstuff/mycoolimage.jpg to simply ~/cool/

Jun 30, 2011 at 4:40 PM

psy, can you publish the project on codeplex? i see a link to the project but it's not published yet. Only ask because I prefer to have access to source of the modules I use, in case I need to make any changes. Thanks!

Jun 30, 2011 at 4:41 PM

btw- the reason i asked about mapping to files- i need to map some root paths to some content files, so I don't want to map the entire root path ;)

Jun 30, 2011 at 5:20 PM

The full source should be available in the gallery version. I will publish the source soon (never done it before).

Jun 30, 2011 at 7:18 PM

cool. Im now using it to map my favicon.ico to the root folder (wanted it there because some client automatically look in the root)... will likely use it for a few other files too. thanks.

Jun 30, 2011 at 7:19 PM

the site ill be using it on is http://www.setiri.com , ill be moving the site to the orchard version today.

Jun 30, 2011 at 7:44 PM

mapping the favicon.ico file is actually a great use for this. I hadn't thought of using it for that, but I will be doing that now as well :)

Jun 30, 2011 at 8:16 PM

psy, i just noticed it is case sensitive. think could add a switch to allow non-case sensitive matches? (without becoming a full blown url rewriting tool ;)

 

Jun 30, 2011 at 9:40 PM

It's probably easy enough to change it so the route matching is case insensitive. 

Developer
Nov 4, 2011 at 10:21 AM

How can I configure a virtual directory manually ?

If I create a virtual directory in IIS called "Images" pointing to "/Media/Images/", the files are not accessible.

Coordinator
Nov 4, 2011 at 5:49 PM

Did you put a web.config in there?

Developer
Nov 4, 2011 at 6:49 PM

OK, it works if I copy the same web.config than in the Media foler

Dec 13, 2011 at 11:24 PM
Edited Dec 13, 2011 at 11:24 PM

Hello guys,

string mimetype = VirtualMediaHelper.GetMimeType(physicalPath);

is returning NULL so for quick testing I've had to:

if (string.IsNullOrEmpty(mimetype)) mimetype="application/pdf"; 

Any ideas why GetMemeType would start returning null?

NOTE: In my source dev project this does not occur, only on the client server in release mode...

Thank you

Coordinator
Dec 13, 2011 at 11:35 PM

There is no such VirtualMediaHelper in Orchard, must be an external module

Dec 14, 2011 at 12:42 AM

sebastien, as per the title of this thread, yes it is a module ;)