is there a way to force the media files being served with the real folder names entered in the media section instead of the folder IDs (so its /media/pdf/file.pdf instead of /media/644/file.pdf)?
Not with the build in methods. You can either choose to place the medias in subfolders with the property ids (/media/644/file.pdf) or to use it in a flat manner (/media/644_file.pdf [or similiar])
As thomas is suggesting, you can't out-of-the-box, but you can if you have some programming knowledge. You can either change location of a uploaded file on create or update of a media file using the event system (be aware tho to update all relevant properties as eg. the rich text editor uses path info to build the links) or build your own upload datatype and store all info yourself.
Would it be very hard to make a structure like this, when you upload a PDF file for instance?
/media/pdf/(id)/first.pdf /media/pdf/(id)/second.pdf etc.
Is it possible and if so, what should one then be aware of?
I need to make sure that I can block access to the PDF files through robots.txt so they don't get indexed by search engines but unfortunately one can't trust the * to "work" in a robots.txt file...otherwise it would have been easy and I would not have a problem :)
Yup, it can be done, and there's several possibilities:
Inherit from the existing uploadField implementation and 'override' the Save() method. Bit of a hack, as you'll have to use the new keyword the hide the existing implementation (but that works). Also, as your class will be different from the uploadField class, you'll have to build your loadMedia implementation which is used to build the media tree and media picker dialog (as those rely on the guid of the media type)
Thanks for your pointers. I must admit I'm not sure that I myself have the skills to do what is neccesary to make it work. To me it sounds like it's going to take long time, to get it right.
I'm also thinking it should not be neccesary to make a change to the media library to make sure that PDF files are not being crawled by search engines. Does anyone have a simple solution to manage that task? As far as I know it's not possible to use *.pdf in robots.txt.
I got some help from a colleague today to help me achieve my goal. Basically we made a new datatype where we copied the original soruce files, changed name and guid of course and then we made an if sequence to see if the uploaded file ends with "PDF". If so we create a PDF folder in the library. Works like a charm.
However there is still one problem though. At the moment it's not possible to use the media-picker in the rich text editor to select the PDF file, when one wants to insert a link to it on a textpage.
In the dialogue it's visible but with a grey color, instead of black. Since it's grey it cannot be selected and no link is being inserted.
What is it that we need to do further to finish the job?
Yup, you need to add your new datatype's guid to the list of LinkableMediaDatatypes either on application startup or inherit from loadMedia and override the GetLinkValue(Media m, string nodeLink) method. I prefer the second method but that requires an additional db change (loadMedia replace by your custom 'load' class)
I'm experiencing something odd. I got the stuff with the media-picker working by following Dirk's suggestion but all of the sudden it does not work anymore.
I tried changing the GUID to see if that would fix it but it does'nt. I'm a bit puzzled about this. I don't think anyone else could have overwritten er changed anything.
In my pdfDataTypeUploadField.cs I have the following code for the GUID
public override Guid Id { get { return new Guid("{C622B4B4-F5DC-47a6-840F-696B9A20Y309}"); } }
and in my PdfUploadField.cs I have the following
public PdfUploadField(umbraco.interfaces.IData Data, string ThumbnailSizes) { _data = (umbraco.cms.businesslogic.datatype.DefaultData)Data; _thumbnails = ThumbnailSizes; if (!umbraco.loadMedia.LinkableMediaDataTypes.Contains(new Guid("{C622B4B4-F5DC-47a6-840F-696B9A20Y309}"))) umbraco.loadMedia.LinkableMediaDataTypes.Add(new Guid("{C622B4B4-F5DC-47a6-840F-696B9A20Y309}")); }
Is there anything else that I need to do to get this to work properly? Something that I have missed?
Media folder name
Hi,
is there a way to force the media files being served with the real folder names entered in the media section instead of the folder IDs (so its /media/pdf/file.pdf instead of /media/644/file.pdf)?
Thx,
André
Not with the build in methods. You can either choose to place the medias in subfolders with the property ids (/media/644/file.pdf) or to use it in a flat manner (/media/644_file.pdf [or similiar])
hth, Thomas
Hi André,
As thomas is suggesting, you can't out-of-the-box, but you can if you have some programming knowledge. You can either change location of a uploaded file on create or update of a media file using the event system (be aware tho to update all relevant properties as eg. the rich text editor uses path info to build the links) or build your own upload datatype and store all info yourself.
For some more background info on events, see these wiki pages starting here.
Hope this helps.
Regards,
/Dirk
Thanks for that. It would have been nice, but actually isn't too bad.
Hi guys
Would it be very hard to make a structure like this, when you upload a PDF file for instance?
/media/pdf/(id)/first.pdf
/media/pdf/(id)/second.pdf
etc.
Is it possible and if so, what should one then be aware of?
I need to make sure that I can block access to the PDF files through robots.txt so they don't get indexed by search engines but unfortunately one can't trust the * to "work" in a robots.txt file...otherwise it would have been easy and I would not have a problem :)
Looking forward to hear from you guys.
/Jan
Yup, it can be done, and there's several possibilities:
Inherit from the existing uploadField implementation and 'override' the Save() method. Bit of a hack, as you'll have to use the new keyword the hide the existing implementation (but that works). Also, as your class will be different from the uploadField class, you'll have to build your loadMedia implementation which is used to build the media tree and media picker dialog (as those rely on the guid of the media type)
Hope this helps.
Regards,
/Dirk
Hi Dirk
Thanks for your pointers. I must admit I'm not sure that I myself have the skills to do what is neccesary to make it work. To me it sounds like it's going to take long time, to get it right.
I'm also thinking it should not be neccesary to make a change to the media library to make sure that PDF files are not being crawled by search engines. Does anyone have a simple solution to manage that task? As far as I know it's not possible to use *.pdf in robots.txt.
Any thoughts?
/Jan
Hi again
I got some help from a colleague today to help me achieve my goal. Basically we made a new datatype where we copied the original soruce files, changed name and guid of course and then we made an if sequence to see if the uploaded file ends with "PDF". If so we create a PDF folder in the library. Works like a charm.
However there is still one problem though. At the moment it's not possible to use the media-picker in the rich text editor to select the PDF file, when one wants to insert a link to it on a textpage.
In the dialogue it's visible but with a grey color, instead of black. Since it's grey it cannot be selected and no link is being inserted.
What is it that we need to do further to finish the job?
/Jan
Yup, you need to add your new datatype's guid to the list of LinkableMediaDatatypes either on application startup or inherit from loadMedia and override the GetLinkValue(Media m, string nodeLink) method. I prefer the second method but that requires an additional db change (loadMedia replace by your custom 'load' class)
Cheers,
/Dirk
Thank you very much Dirk. I will look into it first thing tomorrow. I love this community :-)
/Jan
Hello again
I'm experiencing something odd. I got the stuff with the media-picker working by following Dirk's suggestion but all of the sudden it does not work anymore.
I tried changing the GUID to see if that would fix it but it does'nt. I'm a bit puzzled about this. I don't think anyone else could have overwritten er changed anything.
In my pdfDataTypeUploadField.cs I have the following code for the GUID
and in my PdfUploadField.cs I have the following
Is there anything else that I need to do to get this to work properly? Something that I have missed?
/Jan
is working on a reply...