[Zope] Re: Python Script Trouble

Tres Seaver tseaver at zope.com
Mon Nov 8 15:55:26 EST 2004


Laura McCord wrote:
> I am having a problem with finding the uploaded fileSize. Currently whe
> I use the file.read() function when I view the contents of the file
> after it is uploaded it is blank. Perhaps, someone can see what I am
> doing wrong.

Just a guess, but double-check that your form has the upload-enabling 
'enctype="multipart-formdata"' incantation set;  otherwise, the request 
will just have the filename, rather than the uploaded file.

> Here is my code:
> 
> # I am passing the uploaded file, title, id ....
> REQUEST = context.REQUEST
> new_context = context.portal_factory.doCreate(context, id)
> 
> # Generic editing method (ie. edits id + Metadata)
> new_context.plone_utils.contentEdit(new_context, id = id, title = title,
> )
> 
> spaceAvail = context.Availability()
> 
> data = file.read()
> fileSize = len(data)
> 
> if spaceAvail < 80:
>  if fileSize < 30:
>   sizeTest = context.getDirectories('/var/www/html/da')
>   totalSize = fileSize + sizeTest
>   if totalSize > 900:
>    message = 'Failure: No available disk space, see system
> administrator'
>    return ('failure', new_context,{'portal_status_message':message})
>   else:
>    test = new_context.manage_editPloneExternalFile(title = title,file =
> file,REQUEST = REQUEST)
>    if not test:
>     return ('success',
> new_context,{'portal_status_message':context.REQUEST.get('portal_status_
> message', 'Content updated.')})
>    else:
>     return ('failure', new_context,{'portal_status_message':test})
>  else:
>   errormsg = 'Failure: File exceeds size limitation of 30MB'
>   return ('failure', new_context,{'portal_status_message':fileSize})
> else:
>  errormsg2 = 'Failure: No disk space available in /var directory'
>  return ('failure', new_context,{'portal_status_message':errormsg2})
> 

Tres.
-- 
===============================================================
Tres Seaver                                tseaver at zope.com
Zope Corporation      "Zope Dealers"       http://www.zope.com



More information about the Zope mailing list