Skip to content

Instantly share code, notes, and snippets.

@yushangdi
Last active December 11, 2023 21:39
Show Gist options
  • Select an option

  • Save yushangdi/b966dc8625e3bae9e5a7f4e222d39500 to your computer and use it in GitHub Desktop.

Select an option

Save yushangdi/b966dc8625e3bae9e5a7f4e222d39500 to your computer and use it in GitHub Desktop.
upload files to zenoto
import requests
ACCESS_TOKEN = 'TOKEN'
r = requests.get('https://zenodo.org/api/deposit/depositions',
params={'access_token': ACCESS_TOKEN})
r.status_code
# 200
# print(r.json())
# []
headers = {"Content-Type": "application/json"}
params = {'access_token': ACCESS_TOKEN}
r = requests.post('https://zenodo.org/api/deposit/depositions',
params=params,
json={},
headers=headers)
r.status_code
# 201
# print(r.json())
# need to upload a random file first to activate bucket link
# deposition_id = r.json()[0]['id']
# data = {'name': 'test.csv'}
# files = {'file': open('/Users/sy/Desktop/MIT/clusterer/data/birds.npy', 'rb')}
# r = requests.post('https://zenodo.org/api/deposit/depositions/%s/files' % deposition_id,
# params={'access_token': ACCESS_TOKEN}, data=data,
# files=files)
bucket_url = r.json()['links']['bucket']
''' New API '''
filename = "file"
path = "path to file/%s" % filename
'''
The target URL is a combination of the bucket link with the desired filename
seperated by a slash.
'''
with open(path, "rb") as fp:
r = requests.put(
"%s/%s" % (bucket_url, filename),
data=fp,
params=params,
)
print(r.json())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment