Last active
October 26, 2018 15:02
-
-
Save jbenito3/b4508a00d79771a4b5a7e50292d952d1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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