Created
December 17, 2013 10:45
-
-
Save iamkhush/8003048 to your computer and use it in GitHub Desktop.
Read zip fie from form upload..
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
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