I'm using LocalFS as a repository for uploading files. Many files are relatively large, perhaps in the 10-20 Meg range. Is the file cached by Zope and then written to the filesystem all at once or is it written to the filesystem in incrementally? From the product code below, it looks like it it writing directly to the path location... What happens if someone is uploading a file and their net connection is broken? How would this be handled? Could this result in a partial file being cached somewhere that needs to be purged or perhaps a write process that needs to be killed off? Thanks, -- David Here's what I think is the relevant code from the product... def manage_upload(self, file, id='', action='manage_workspace', REQUEST=None): """Upload a file to the local file system. The 'file' parameter is a FileUpload instance representing the uploaded file.""" if hasattr(file,'filename'): filename=file.filename else: filename=file.name if not id: if '/' in filename: id=filename[string.rfind(filename,'/')+1:] elif '\\' in filename: id=filename[string.rfind(filename,'\\')+1:] elif ':' in filename: id=filename[string.rfind(filename,':')+1:] else: id=filename try: self._checkId(id,1) except: raise 'Upload Error', MessageDialog( title='Invalid Id', message=sys.exc_value, action ='manage_main') path = self._getpath(id) if os.path.exists(path): self.manage_overwrite(file, path, REQUEST) else: self._write_file(file, path) if REQUEST: return MessageDialog( title='Success!', message='Your file has been uploaded.', action=action)
David Siedband wrote at 2003-8-15 20:28 -0700:
Is the file cached by Zope and then written to the filesystem all at once or is it written to the filesystem in incrementally? From the product code below, it looks like it it writing directly to the path location...
But, writing is not atomically (even if it seems to be).
What happens if someone is uploading a file and their net connection is broken?
The net connection is not a problem. ZServer has stored the file in its entirety to a temporary file (on your server) before Zope even sees the request. But you can get other problems during the store (e.g. file system is full).
How would this be handled? Could this result in a partial file being cached somewhere that needs to be purged or perhaps a write process that needs to be killed off?
You have to look at the LocalFS sources to answer these questions. If it does nothing special (i.e. "try: ... except: ...) and clean up in case of an exception, then you can get a partial file. Dieter
participants (2)
-
David Siedband -
Dieter Maurer