Skip to content

Commit

Permalink
Add upload check for UPLOAD_MAX_SIZE
Browse files Browse the repository at this point in the history
  • Loading branch information
GraemeWatt committed Apr 20, 2021
1 parent 1db0edd commit fc29cb5
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions hepdata_cli/api.py
Expand Up @@ -12,6 +12,7 @@
SITE_URL = "https://www.hepdata.net"
# SITE_URL = "http://127.0.0.1:5000"

UPLOAD_MAX_SIZE = 52000000 # Upload limit in bytes

MAX_MATCHES, MATCHES_PER_PAGE = (10000, 10) if "pytest" not in sys.modules else (144, 12)

Expand Down Expand Up @@ -119,6 +120,9 @@ def upload(self, path_to_file, email, recid=None, invitation_cookie=None, sandbo
:sandbox: True (default) or False if the file should be uploaded to the sandbox.
:password: password of existing HEPData user (prompt if not specified).
"""
file_size = os.path.getsize(path_to_file)
assert file_size < UPLOAD_MAX_SIZE,\
'{} too large ({} bytes > {} bytes)'.format(path_to_file, file_size, UPLOAD_MAX_SIZE)
files = {'hep_archive': open(path_to_file, 'rb')}
data = {'email': email, 'recid': recid, 'invitation_cookie': invitation_cookie, 'sandbox': sandbox, 'pswd': password}
resilient_requests('post', SITE_URL + '/record/cli_upload', data=data, files=files)
Expand Down

0 comments on commit fc29cb5

Please sign in to comment.