Parallel file uploading via Browser using Python
<p>The following code uploads multiple files from a browser in a serial fashion to a host. In order to make the process faster, how could the files be processed in parallel so there are multiple streams being sent to the server? Is this worth pursuing if the files are being sent to the same host? Will a browser allow multiple upload streams to the same host? If so, how might this work?</p>

<p>I assume that is not possible to break the file into parts and write them parallel similar to this <a href="https://bitbucket.org/fabian/filechunkio/changeset/1960eeb8df4c5d9d5f916dd76534aa9c552de6cc" rel="nofollow">example</a> since they are being submitted by a browser rather then a Python client.</p>

<pre><code>#!/usr/bin/python
import cgi, os
import shutil
import cgitb; cgitb.enable()  # for troubleshooting

form = cgi.FieldStorage()

print """\
Content-Type: text/html\n
&lt;html&gt;&lt;body&gt;
"""

if 'file' in form:
   filefield = form['file']
   if not isinstance(filefield, list):
      filefield = [filefield]

   for fileitem in filefield:
       if fileitem.filename:
          fn = os.path.basename(fileitem.filename)
          # save file
          with open('/var/www/site/files/' + fn, 'wb') as f:
              shutil.copyfileobj(fileitem.file, f)
          # line breaks are not occuring between interations
          print 'File "' + fn + '" was uploaded successfully&lt;br/&gt;'
          message = 'All files uploaded'
else:
   message = 'No file was uploaded'

print """
&lt;p&gt;%s&lt;/p&gt;
&lt;/body&gt;&lt;/html&gt;
""" % (message)
</code></pre>
