Skip to content

Instantly share code, notes, and snippets.

@jbenito3
Last active October 26, 2018 15:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jbenito3/b4508a00d79771a4b5a7e50292d952d1 to your computer and use it in GitHub Desktop.
Save jbenito3/b4508a00d79771a4b5a7e50292d952d1 to your computer and use it in GitHub Desktop.
# Provide the Deposit ID, access token
depid = DEPOSIT_ID
params = {'access_token': ACCESS_TOKEN}
filename = 'myfile.zip'
# Get the deposit resource as in the old API
headers = {'Content-Type': 'application/json'}
r = requests.get('https://zenodo.org/api/deposit/depositions/{depid}'.format(depid=depid),
params=params, json={}, headers=headers)
# In new files API we use a PUT request to a 'bucket' link, which is the container for files
bucket_url = r.json()['links']['bucket'] # bucket url looks like this: 'https://zenodo.org/api/files/12341234-abcd-1234-abcd-0e62efee00c0'
# We pass the file object (fp) directly to request as 'data' for stream upload
# the target URL is the URL of the bucket and the desired filename on Zenodo seprated by slash
with open(filename, 'rb') as fp:
requests.put(bucket_url + '/' + filename,
params=params,
data=fp)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment