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><a href="https://docs.python.org/2/library/zipfile.html#zipfile.ZipFile.write" rel="nofollow"><code>ZipFile.write(filename, [arcname[, compress_type]])</code></a> takes the name of a local file to be added to the zip file. To write data from a <code>bytearray</code> or <code>bytes</code> object you need to use the <a href="https://docs.python.org/2/library/zipfile.html#zipfile.ZipFile.writestr" rel="nofollow"><code>ZipFile.writestr(zinfo_or_arcname, bytes[, compress_type])</code></a> method instead:</p>

<pre><code>with zipfile.ZipFile(zipPath, 'w'):
    zipFile.write('name_of_file_in_archive', zipContents)
</code></pre>

<p>Note: if <code>request.POST.get("zipFile")</code> already is <code>bytes</code> (or <code>str</code> in python2) you don't need to convert it to a <code>bytearray</code> before writing it to the archive.</p>

python python-3.x zipfile