Skip to content

Commit

Permalink
allows for file-like uploads
Browse files Browse the repository at this point in the history
  • Loading branch information
cmhedrick committed Dec 2, 2015
1 parent 40a7224 commit 0e45c4a
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions vimeo/upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,23 @@ def _perform_upload(self, filename, ticket):

# Perform the actual upload.
target = ticket['upload_link']
size = os.path.getsize(filename)
last_byte = 0
with io.open(filename, 'rb') as f:
# Try to get size of obj by path. If provided obj is not a file path
# find the size of file-like object.
try:
size = os.path.getsize(filename)
with io.open(filename, 'rb') as f:
while last_byte < size:
try:
self._make_pass(target, f, size, last_byte)
except requests.exceptions.Timeout:
# If there is a timeout here, we are okay with it, since
# we'll check and resume.
pass
last_byte = self._get_progress(target, size)
except TypeError:
size = len(filename.read())
f = filename
while last_byte < size:
try:
self._make_pass(target, f, size, last_byte)
Expand Down

0 comments on commit 0e45c4a

Please sign in to comment.