Creating zip file from byte
<p>I'm sending byte string of a zip file from client side using <code>JSZip</code> and need to convert it back to zip on server side. the code I've tried isn't working.</p>

<pre><code>b = bytearray()
b.extend(map(ord, request.POST.get("zipFile")))

zipPath = 'uploadFile' + str(uuid.uuid4()) + '.zip'
myzip = zipfile.ZipFile(zipPath, 'w') 
with  myzip:
    myzip.write(b)
</code></pre>

<p>It gives the error:</p>

<pre><code>stat: path too long for Windows 
</code></pre>

<p>How do I save my byte string as a zip file?</p>

<p>JSZip already made a zip archive. The zipfile module is for accessing zip file contents, but you don't need to parse it to store it. In addition, bytearray can be created directly from strings so the map(ord,) is superfluous, and write can handle strings as well (bytearray is for handling numeric binary data or making a mutable stringlike object). So a slightly simplified variant might be:</p>

<pre><code>zipContents = request.POST.get("zipFile")
zipPath = 'uploadFile' + str(uuid.uuid4()) + '.zip'
with open(zipPath, 'wb') as zipFile:
    zipFile.write(zipContents)
</code></pre>

python python-3.x zipfile