Created
May 1, 2011 20:44
-
-
Save mdornseif/950860 to your computer and use it in GitHub Desktop.
This is shows how to generate ZIP files in the blobstore.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def store_pdfs_in_zip(): | |
docs = Dokument.all().order('updated_at') | |
file_name = files.blobstore.create(mime_type='application/zip', | |
_blobinfo_uploaded_filename='test.zip') | |
with files.open(file_name, 'w') as f: | |
z = blobstoreZipFile(f) | |
for doc in docs.fetch(75): | |
pdf = doc.data | |
fname = "%s-%s.pdf" % (doc.designator, doc.updated_at) | |
fname = fname.encode('ascii', 'replace') | |
z.writestr(fname, pdf, date_time=doc.updated_at.timetuple()[:6]) | |
# Finalize ZIP file and write directory | |
z.flush() | |
# Finalize the file in the blobstore | |
files.finalize(file_name) | |
# Get the file's blob key | |
blob_key = files.blobstore.get_blob_key(file_name) |
Thanks for sharing this. The files generated are seen like corrupted. Did you get this:
carlo@carlo-laptop:/tmp$ unzip -l /tmp/pages.zip Archive: /tmp/pages.zip warning [/tmp/pages.zip]: 60 extra bytes at beginning or within zipfile (attempting to process anyway) error [/tmp/pages.zip]: reported length of central directory is -60 bytes too long (Atari STZip zipfile? J.H.Holm ZIPSPLIT 1.1 zipfile?). Compensating... Length Date Time Name --------- ---------- ----- ---- 2537 2011-09-27 16:13 000001.pickled --------- ------- 2537 1 file
Despite the errors, I can extract zipped files:
carlo@carlo-laptop:/tmp$ unzip -x pages.zip Archive: pages.zip warning [pages.zip]: 60 extra bytes at beginning or within zipfile (attempting to process anyway) error [pages.zip]: reported length of central directory is -60 bytes too long (Atari STZip zipfile? J.H.Holm ZIPSPLIT 1.1 zipfile?). Compensating... inflating: 000001.pickled
@carlopires I tested it and then moved to tar.bz2
. Did you check the actual contents of the file?
hexdump -C /tmp/pages.zip | head -n 20
Do you mean the file generated is bzip2 compressed?
The code I currently use is in https://gist.github.com/950846#file_replication.py
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Do you have enabled Billing?