Cannot upload compressed zipfile

9 views
Skip to first unread message

fred....@sunrise.com

unread,
Jul 24, 2011, 9:58:12 AM7/24/11
to django...@googlegroups.com
I'm using python 2.4, Django 1.2.1.  If this is resolved in a later version, I can upgrade but this system has been running smoothly in production for a year and management resists those types of upgrades unless I can clearly identify that it has been solved in 1.3

I want to upload a zipfile (sent from Adobe's flex/flash) without writing a tmp file.  I can do this if the file was not compressed.  The code I use to create the zipfile is...

    zipper = zipfile.ZipFile(path, mode='w')
    for assessment in assessments:
        docid = assessment['FAC_DOC_ID']
        xmlfilename =  docid+".xml"
        xmltext = xmlbuilder.getXML(assessment)
        zipper.writestr(xmlfilename, xmltext)
    zipper.close()

and I can read this in views.py  with...
def upload(request, *args, **kwargs):
    filedata = request.FILES['Filedata']
    buffer = filedata.read()
....
    zipper = ZipString(buffer)
        for name in zipper.namelist():
            content = zipper.read(name)
            x = process_xml_file(name, content)

_____________________________________
but when I try to upload a zipfile from a vendor of the same data that is compressed I get a badzipfile error.

zipfile.BadZipfile: File is not a zip file

  I'm wondering if the request adds/removes some header/trailer that messes up a zipfile if that file is binary (compressed) rather than ASCII (uncompressed).

I've been on this for several days and am really stuck.  I tried to send a similar request via email but had trouble getting past company security.  If this has been asked an answered I sincerely apologize.

Fred.

fred....@sunrise.com

unread,
Jul 29, 2011, 11:21:05 AM7/29/11
to django...@googlegroups.com
solved problem, method of joining buffer was corrupting data.  you need to use something like

buffer ='''
for x in f.read(4096):
    buffer+=x


the solution in django works.
Reply all
Reply to author
Forward
0 new messages