Skip to content

Commit

Permalink
Avoid errors when uploading large files (#94)
Browse files Browse the repository at this point in the history
Reading/writing a large file all at once can cause a MemoryError or
an OverflowError. Using `shutil.copyfileobj` seems to solve the issue.
  • Loading branch information
eestrada authored and victoriagrey committed Mar 13, 2019
1 parent cb70773 commit 832ef7d
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion shotgun_api3/shotgun.py
Original file line number Diff line number Diff line change
Expand Up @@ -4040,7 +4040,9 @@ def encode(self, params, files, boundary=None, buffer=None):
buffer.write('Content-Type: %s\r\n' % content_type)
buffer.write('Content-Length: %s\r\n' % file_size)
fd.seek(0)
buffer.write('\r\n%s\r\n' % fd.read())
buffer.write('\r\n')
shutil.copyfileobj(fd, buffer)
buffer.write('\r\n')
buffer.write('--%s--\r\n\r\n' % boundary)
buffer = buffer.getvalue()
return boundary, buffer
Expand Down

0 comments on commit 832ef7d

Please sign in to comment.