Last active
December 11, 2023 21:39
-
-
Save yushangdi/b966dc8625e3bae9e5a7f4e222d39500 to your computer and use it in GitHub Desktop.
upload files to zenoto
This file contains hidden or 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
| 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