Skip to content

Commit

Permalink
enable large file uploads
Browse files Browse the repository at this point in the history
  • Loading branch information
ajsierakowski committed Nov 18, 2019
1 parent b4c8ce2 commit 1828b23
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 11 deletions.
2 changes: 1 addition & 1 deletion craedl/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

from craedl.core import Profile

__version__ = '0.1.0'
__version__ = '0.1.1'

def auth():
return Profile()
22 changes: 14 additions & 8 deletions craedl/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@

from craedl import errors

BUF_SIZE = 104857600

class Auth():
"""
This base class handles low-level RESTful API communications. Any class that
Expand Down Expand Up @@ -100,14 +102,18 @@ def PUT_DATA(self, path, data):
an HTML error string if the response does not have status 200
"""
token = open(os.path.expanduser(self.token_path)).readline().strip()
response = requests.put(
self.base_url + path,
data=data,
headers={
'Authorization': 'Bearer %s' % token,
'Content-Disposition': 'attachment; filename="craedl-upload"',
},
)
while True:
d = data.read(BUF_SIZE)
if not d:
break
response = requests.put(
self.base_url + path,
data=d,
headers={
'Authorization': 'Bearer %s' % token,
'Content-Disposition': 'attachment; filename="craedl-upload"',
},
)
return self.process_response(response)

def GET_DATA(self, path):
Expand Down
4 changes: 2 additions & 2 deletions craedl/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@ def __str__(self):
class Invalid_Token_Error(Exception):
def __init__(self):
self.message = 'Your configured authentication token is invalid.\n'
self.message += ' Use `craedl-token` to configure your authentication token.'
self.message += ' Use `python -m craedl` to configure your authentication token.'

def __str__(self):
return self.message

class Missing_Token_Error(Exception):
def __init__(self):
self.message = 'You have not configured an authentication token.\n'
self.message += ' Use `craedl-token` to configure your authentication token.'
self.message += ' Use `python -m craedl` to configure your authentication token.'

def __str__(self):
return self.message
Expand Down

0 comments on commit 1828b23

Please sign in to comment.