#49 — Migration cannot handle all instance types form FileField

State Unconfirmed
Version: 2.8rc2
Area Functionality
Issue type Bug
Severity Medium
Submitted by Webworks
Submitted on Jul 08, 2010
Responsible
Target release:
Version 2.8rc3 tested.

The following monkeypatch allows iw.fss to migrate fields with OFS.Image.Pdata instances as values. This happened on our server when tarballs (.tar.gz files) where stored. OFS.Image.Pdata does not have a "read" method and so iw.fss.FileSystemStorage.FileUploadIterator throws an error. Here's the monkey patch:

import cgi
from ZPublisher.HTTPRequest import FileUpload
import cStringIO
from iw.fss.FileSystemStorage import FileUploadIterator

old__init__ = FileUploadIterator.__init__

def new__init__(self, file, streamsize=1<<16):
    """ this is a file upload """
    if not hasattr(file, 'read') and hasattr(file,'data'):
        data = str(file) # see OFS.Image.Pdata
        fs = cgi.FieldStorage()
        fs.file = cStringIO.StringIO(data)
        file = FileUpload(fs)
    return old__init__(self, file, streamsize)
Steps to reproduce:
On our servers:
Tried to migrate 850 documents with filefields to iw.fss, some would fail. Patch solved it.

No responses can be added.