~azzar1/unity/add-show-desktop-key

« back to all changes in this revision

Viewing changes to www/apps/fileservice/action.py

  • Committer: mattgiuca
  • Date: 2008-01-14 05:56:44 UTC
  • Revision ID: svn-v3-trunk0:2b9c9e99-6f39-0410-b283-7f802c844ae2:trunk:226
fileservice/action: putfile now correctly handles empty files.

Show diffs side-by-side

added added

removed removed

Lines of Context:
280
280
 
281
281
    Reads fields: 'path', 'data' (file upload)
282
282
    """
 
283
    # Important: Data is "None" if the file submitted is empty.
283
284
    path = fields.getfirst('path')
284
285
    data = fields.getfirst('data')
285
 
    if path is None or data is None:
 
286
    if path is None:
286
287
        raise ActionError("Required field missing")
287
288
    path = actionpath_to_local(req, path)
288
 
    data = data.file
 
289
    if data is not None:
 
290
        data = data.file
289
291
 
290
292
    # Copy the contents of file object 'data' to the path 'path'
291
293
    try:
292
294
        dest = open(path, 'wb')
293
 
        shutil.copyfileobj(data, dest)
 
295
        if data is not None:
 
296
            shutil.copyfileobj(data, dest)
294
297
    except OSError:
295
298
        raise ActionError("Could not write to target file")
296
299