Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #127 from mhavard999/master

save file data using shutil.copyfileobj
  • Loading branch information...
commit 64c50d9de32bba7c1febdc563d22fd16080f00ba 2 parents d405e5f + ae79edd
Michael Merickel mmerickel authored
Showing with 3 additions and 11 deletions.
  1. +3 −11 forms/file_uploads.rst
14 forms/file_uploads.rst
View
@@ -28,6 +28,7 @@ request object as a ``cgi.FieldStorage`` object accessible through the
import os
import uuid
+ import shutil
from pyramid.response import Response
def store_mp3_view(request):
@@ -56,20 +57,11 @@ request object as a ``cgi.FieldStorage`` object accessible through the
# being used.
temp_file_path = file_path + '~'
- output_file = open(temp_file_path, 'wb')
# Finally write the data to a temporary file
input_file.seek(0)
- while True:
- data = input_file.read(2<<16)
- if not data:
- break
- output_file.write(data)
-
- # If your data is really critical you may want to force it to disk first
- # using output_file.flush(); os.fsync(output_file.fileno())
-
- output_file.close()
+ with open(temp_file_path, 'wb') as output_file:
+ shutil.copyfileobj(input_file, output_file)
# Now that we know the file has been fully saved to disk move it into place.
Please sign in to comment.
Something went wrong with that request. Please try again.