Skip to content

Instantly share code, notes, and snippets.

@iamkhush
Created December 17, 2013 10:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save iamkhush/8003048 to your computer and use it in GitHub Desktop.
Save iamkhush/8003048 to your computer and use it in GitHub Desktop.
Read zip fie from form upload..
try:
# Get Compressed folder information
read_compressed_folder(request.FILES['compressed_folder'].temporary_file_path())
except Exception:
# When storing in memory
if not os.path.exists(os.path.join(tempfile.gettempdir(), 'temp_compressed_folder')):
os.makedirs(os.path.join(tempfile.gettempdir(), 'temp_compressed_folder'))
zip_file = zipfile.ZipFile(request.FILES['compressed_folder'])
zf = zipfile.ZipFile(os.path.join(tempfile.gettempdir(), 'zipfile_write.zip'), mode='w')
for f in zip_file.namelist():
source = zip_file.open(f)
compress_file = open(os.path.join(tempfile.gettempdir(), os.path.basename(f)), 'w+')
compress_file.write(source.read())
compress_file.close()
zf.write(os.path.join(tempfile.gettempdir(), compress_file.name))
zf.close()
read_compressed_folder(os.path.join(tempfile.gettempdir(), 'zipfile_write.zip'))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment