Skip to content

Instantly share code, notes, and snippets.

@slint
Created October 25, 2017 13:12
Show Gist options
  • Save slint/c09ecd6cc4a6992cc452f627f3111623 to your computer and use it in GitHub Desktop.
Save slint/c09ecd6cc4a6992cc452f627f3111623 to your computer and use it in GitHub Desktop.
with open(config.get_deposition_file()) as f:
deposition_id = f.read()
# create a new deposition version with different deposition_id from the existing deposition
r = requests.post(config.url + '/api/deposit/depositions/' + deposition_id + '/actions/newversion',
params={'access_token': config.access_token})
# You have to use the new version's deposit link
newversion_draft_url = r.json()['links']['latest_draft']
# There is a new "deposition_id" now:
deposition_id = newversion_draft_url.split('/')[-1] # Extract deposition_id from url
################## ACTIONS ####################
# 2. upload a new file to this existing deposition
data = {'filename': config.file_name_to_upload}
files = {'file': open(file_path_to_upload, 'rb')}
r = requests.post(newversion_draft_url + '/files', # <--- Notice the use of the new link
params={'access_token': config.access_token}, data=data,
files=files)
print r
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment