Thanks a lot.
We're going into production on thursday and are using your suggestions.
I added code like this to the validate_file_edit.cpy (and thats all I needed
to do for a quick and dirty solution):
###nsk extension
if filename!=None:
file.seek(0, 2)
filesize=file.tell()
maxsize=pow(1024,2)*0.5 #0.5 mb restriction
fileExt = filename.split('.')[-1:]
if fileExt not in (['xls'],['XLS']) or filesize>maxsize:
state.setError('file','You can only attach xls files to this object
less than 0.5 MB. Your file-extension and filesize are:
%s%s'%(fileExt,filesize) )
On Mon, 22 Aug 2005 11:18:50 -0400, Dave Zoltok wrote
> Archetypes includes a validator class that allows you to specify the
> maximum file size of a given uploaded file:
>
> validation.register(MaxSizeValidator('checkFileMaxSize',
> maxsize=pow(1024, 2) * 20))
>
> would limit uploaded files to 20MB or less. If you want to apply
> this to the built-in file types, you could create a custom validator
> script similar to the one Archetypes uses, and add an error if the
> file size exceeds whatever your maximum size is. As for the MIME
> types, here's what I used (also in a validator script) to prevent
> users from uploading .ac files:
>
> file = context.REQUEST.get('file', None) # The name of the upload
> field should replace 'file', check the HTML source
>
> if file:
> fileName = file.filename
> fileExt = fileName.split('.')[-1]
> if fileExt == 'ac':
> state.setError('file','You cannot attach a .ac file to this
> object.')
>
> Dave
>
> On 8/21/05, Niels Steen Krogh <nielssteenkrogh@...> wrote:
> > Hi.
> > Using Plone 2.05
> > Want to restrict filesize and MimeType for fileopload - using the standard
> > File type object in plone .
> >
> > How should restrictions for filesize and MimeType be set? (for example 200 kb.
> > and only excel/OpenOffice calc spreadsheet).
> >
> > Any hints?
> >
> > /Niels
> >
> > Niels Steen Krogh
> > Konsulent
> > ZiteLab ApS (under stiftelse)
> >
> > Mail: ---------- nielssteenkrogh@...
> > Telefon: ------- +45 38 88 86 13
> > Mobil: --------- +45 22 67 37 38
> > Adresse: ------- Zitelab ApS (under stiftelse)
> > ---------------- Solsortvej 44
> > ---------------- 2000 F.
> > Web: ----------- http://www.zitelab.dk
> >
> > ZiteLab
> > -Let's Empower Your Data with Webservices
> >
> >
> >
> > -------------------------------------------------------
> > SF.Net email is Sponsored by the Better Software Conference & EXPO
> > September 19-22, 2005 * San Francisco, CA * Development Lifecycle Practices
> > Agile & Plan-Driven Development * Managing Projects & Teams * Testing & QA
> > Security * Process Improvement & Measurement * http://www.sqe.com/bsce5sf
> > _______________________________________________
> > Plone-users mailing list
> > Plone-users@...
> > https://lists.sourceforge.net/lists/listinfo/plone-users
> >
Niels Steen Krogh
Konsulent
ZiteLab ApS (under stiftelse)
Mail: ---------- nielssteenkrogh@...
Telefon: ------- +45 38 88 86 13
Mobil: --------- +45 22 67 37 38
Adresse: ------- Zitelab ApS (under stiftelse)
---------------- Solsortvej 44
---------------- 2000 F.
Web: ----------- http://www.zitelab.dk
ZiteLab
-Let's Empower Your Data with Webservices
|