im trying to compress uploaded files in django using 7zip.
i have successfully implemented compression and decompression of files using 7zip in python but i am not able to figure out how to integrate the same with django uploaded file so that whenever a file is uploaded ,a 7zp format for the same file is create and stored in the disk.
Code used in python for compression :
import subprocess
from py7zr import unpack_7zarchive
import shutil
exe = r"C:\Program Files\7-Zip\7zG.exe"
source = r"C:\profiles\Living in the Light_ A guide to personal transformation.pdf"
target = r"C:\profiles\Living1.7z"
def compress(source,traget):
subprocess.call(exe + " a -t7z \"" + target + "\" \"" + source + "\" -mx=9")
print('file compressed')
def uncompress(target):
shutil.register_unpack_format('7zip', ['.7z'], unpack_7zarchive)
shutil.unpack_archive(target, r'C:\Users\098an\Pictures\Camera Roll')
print('file uncompressed')