I'm trying to export some files generated from my application. I'm
creating a zip file with the file in directly (using Python) and the
zip file is created fine. Then I want to upload that file to the DB to
allow them to download it from the uploads directory. The code snippet
below works fine and a file is uploaded, but the file is corrupted (it
has just a few hundred byeted in it.

db.py
    db.define_table("exportitem",
        SQLField("org_id", db.organisations, notnull=True,
writable=False, default=session.org_id),
        SQLField("app_id", "integer", default=session.app_id,
notnull=True),
        SQLField("proj_id", "integer", default=session.proj_id,
notnull=True),
        SQLField("title", "string", length=50, notnull=True,
label="Title"),
        SQLField("created", "datetime", notnull=True,
default=datetime.today(), label="Created", writable=False),
        SQLField("created_by", db.auth_user, notnull=True,
default=session.user_id, writable=False),
        SQLField("exportfile", "upload", notnull=True),
        migrate=migrate,fake_migrate=fake_migrate)

testzip()
    fname=''.join((str(session.org_id),str(datetime.today())))
    my_crypt = CRYPT(key=auth.settings.hmac_key)
    zname = ''.join((my_crypt(fname)[0],'.zip'))

 
zfile='/'.join((request.env.web2py_path,'applications',request.application,'temp',zname))
#
#
#
#
#   now store the file in the database.
#
    zid=db.exportitem.insert(title='testing the zip file
generator',exportfile=db.exportitem.exportfile.store(open(zfile,'rb')))

Reply via email to