diff --git a/demos/file_upload/file_uploader.py b/demos/file_upload/file_uploader.py index f4af78c5..96789694 100644 --- a/demos/file_upload/file_uploader.py +++ b/demos/file_upload/file_uploader.py @@ -34,13 +34,15 @@ def multipart_producer(boundary, filenames, write): for filename in filenames: filename_bytes = filename.encode() - yield write(b'--%s\r\n' % (boundary_bytes,)) - yield write(b'Content-Disposition: form-data; name="%s"; filename="%s"\r\n' % - (filename_bytes, filename_bytes)) - mtype = mimetypes.guess_type(filename)[0] or 'application/octet-stream' - yield write(b'Content-Type: %s\r\n' % (mtype.encode(),)) - yield write(b'\r\n') + buf = ( + (b'--%s\r\n' % boundary_bytes) + + (b'Content-Disposition: form-data; name="%s"; filename="%s"\r\n' % + (filename_bytes, filename_bytes)) + + (b'Content-Type: %s\r\n' % mtype.encode()) + + b'\r\n' + ) + yield write(buf) with open(filename, 'rb') as f: while True: # 16k at a time. @@ -95,7 +97,6 @@ def put(filenames): method='PUT', headers=headers, body_producer=producer) - print(response)