|
|
Rank: Enthusiast
Joined: 2/5/2008 Posts: 40
|
For one of my websites, I need to limit the type of files that can be uploaded into the media library (through the back end). I originally thought to use an action handler, but after reading around action handlers to remind myself how they work (it's been a while since I coded one), I found a few places that mention they don't work for media items. That's left me pretty much stuck. The only other way I can think of doing it is dragging down the latest version of the source code and hacking away at that. Incidentally, is there an easy way to copy the content of one site to another, so if I did have to go the source code route, could I port the site content into it once I'd rebuilt it. Sorry if I'm missing anything obvious with these questions, I'm currently running purely on coffee so my brain's a little fuzzy :) www.punkyduck.comThe iron heals, mends, fortifies, toughens, vitalizes, enables, engages, entertains, fulfills, instructs, humbles and makes a good door stop... Dave Draper
|
|
 Rank: Addict
Joined: 7/19/2006 Posts: 586 Location: Preston, UK
|
roual,
On the upload data type you could add a regular expression so that if the file name is not accepted type a validation error occurs. This was suggested to me by Kalle in another post I havent tried it yet but in theory it should work!
Regards
Ismail
Level 2 certified. If it aint broke dont fix.
|
|
Rank: Enthusiast
Joined: 2/5/2008 Posts: 40
|
Never thought of that, makes sense though. I'll let you know how I get on, may take a while though, I've never looked at data types before, may require a little background reading :) www.punkyduck.comThe iron heals, mends, fortifies, toughens, vitalizes, enables, engages, entertains, fulfills, instructs, humbles and makes a good door stop... Dave Draper
|
|
 Rank: Addict
Joined: 7/19/2006 Posts: 586 Location: Preston, UK
|
Roaul,
If you look at the media types say file one and look at the upload property you can see their that you can add a reg ex thats where the reg ex needs to go. I am going to have a go later today ill post results.
Regards
Ismail
Level 2 certified. If it aint broke dont fix.
|
|
 Rank: Addict
Joined: 7/19/2006 Posts: 586 Location: Preston, UK
|
Roual, This works nicely. I added the following reg ex to my document type Code: ([a-zA-Z]:(\\w+)*\\[a-zA-Z0_9]+)?.doc$
this will thus only allow doc types word. You can change extension to whatever you like. Many thanks to Kalle for this suggestion I cant find the original post where he suggested this! Regards Ismail
Level 2 certified. If it aint broke dont fix.
|
|
 Rank: Fanatic
Joined: 7/19/2006 Posts: 437 Location: Göteborg, Sweden
|
Nice that it worked! Who could have guessed that? // ;) Kalle BTW, here it is: http://forum.umbraco.org/yaf_postst5406_Upload-datatype.aspx
" - Yeah I'd like to share your point of view, as long as it's my view too... ( http://www.d-a-d.dk/lyrics/pointofview)
|
|
Rank: Enthusiast
Joined: 2/5/2008 Posts: 40
|
Sorry guys, but I must be having a really bad day. I got the validation working, except for a couple of small problems. 1) the file still saves even if the validation message is displayed. Is it possible to disable the save if the validation is false, and 2) I can't figure out a regular expression that actually does what I want. ok, so number 2 is my problem and once I manage to wake up a little more, I'll get it, but 1 I'm not sure about. www.punkyduck.comThe iron heals, mends, fortifies, toughens, vitalizes, enables, engages, entertains, fulfills, instructs, humbles and makes a good door stop... Dave Draper
|
|
Rank: Enthusiast
Joined: 2/5/2008 Posts: 40
|
Right, I've managed to get the regular expression to do what I want it to do (stupidly easy when I actually sat down and though about it, I hate regular expressions), so I now get an error message displayed when the user uploads an incorrect file type, but I'm still curious if there's a way to stop the upload all together. My first impression is no, because I believe some if not most of the work on the button click is done through Javascript, but then my Javascript skills are not the best, so I could be wrong. Anyone have any idea if it's possible, and if so, how to do it? www.punkyduck.comThe iron heals, mends, fortifies, toughens, vitalizes, enables, engages, entertains, fulfills, instructs, humbles and makes a good door stop... Dave Draper
|
|
 Rank: Addict
Joined: 7/19/2006 Posts: 586 Location: Preston, UK
|
roual,
My form is built using autoform with dynamic set in the validators so they fire and do not allow submit to happen thus file does not get uploaded.
Regards
Ismail
Level 2 certified. If it aint broke dont fix.
|
|
Rank: Enthusiast
Joined: 2/5/2008 Posts: 40
|
Ismail, The problem I'm having is this isn't with a form I've created, it's with the actual media section in Umbraco. The company we built the website for seems determined to use the media section as a general file repository instead of only uploading files that they actually use on the website. It's not a project stopping issue, but it is getting a little annoying explaining to them that it's not designed as a back-up storage space, or a way for their employees to pass zipped files full of holiday photos from their home computer to their work one (don't ask). Hence the wish to stop them uploading something that's not a pre-designated type of file. It's entirely possible I'm missing something and I can still set the validators on the media section differently so they do stop the upload, but for this project, I'm not working with the source code, so I can't see an obvious way of doing it. www.punkyduck.comThe iron heals, mends, fortifies, toughens, vitalizes, enables, engages, entertains, fulfills, instructs, humbles and makes a good door stop... Dave Draper
|
|
 Rank: Addict
Joined: 7/19/2006 Posts: 586 Location: Preston, UK
|
roual,
Ah ok i was thinking front end your trying to restrict backend. If it is still uploading then you may want to create your datatype based on the upload data type which if file is not in correct format actually stop the upload.
Regards
Ismail
Level 2 certified. If it aint broke dont fix.
|
|
Rank: Enthusiast
Joined: 2/5/2008 Posts: 40
|
Hi Ismail, Sorry, I'm a little foggy on this, do you mean create a new data type in .Net then limit that? I can't see a way of using a datatype based on the standard upload datatype to stop uploads (hope that made sense) Cheers www.punkyduck.comThe iron heals, mends, fortifies, toughens, vitalizes, enables, engages, entertains, fulfills, instructs, humbles and makes a good door stop... Dave Draper
|
|
 Rank: Aficionado
Joined: 12/15/2006 Posts: 112
|
Think you could "roll your own" upload data type. Create a user control, drop in your .Net file upload control, handle all the validation yourself and use the umbraco API to create new media.
If you use .Net Reflector or get the source of the original, you could take the Media-creating code from there.
You could then use the "Usercontrol Wrapper" to add your usercontrol into the Umbraco data types, and into a property from there.
___________________________________________________________________________________
Neil
|
|
|
Guest |