MCPcopy Create free account
hub / github.com/ipython/ipython / post_download

Function post_download

tools/gh_api.py:274–303  ·  view source on GitHub ↗

Upload a file to the GitHub downloads area

(project, filename, name=None, description="")

Source from the content-addressed store, hash-verified

272
273
274def post_download(project, filename, name=None, description=""):
275 """Upload a file to the GitHub downloads area"""
276 if name is None:
277 name = os.path.basename(filename)
278 with open(filename, 'rb') as f:
279 filedata = f.read()
280
281 url = "https://api.github.com/repos/{project}/downloads".format(project=project)
282
283 payload = json.dumps(dict(name=name, size=len(filedata),
284 description=description))
285 response = requests.post(url, data=payload, headers=make_auth_header())
286 response.raise_for_status()
287 reply = json.loads(response.content)
288 s3_url = reply['s3_url']
289
290 fields = dict(
291 key=reply['path'],
292 acl=reply['acl'],
293 success_action_status=201,
294 Filename=reply['name'],
295 AWSAccessKeyId=reply['accesskeyid'],
296 Policy=reply['policy'],
297 Signature=reply['signature'],
298 file=(reply['name'], filedata),
299 )
300 fields['Content-Type'] = reply['mime_type']
301 data, content_type = encode_multipart_formdata(fields)
302 s3r = requests.post(s3_url, data=data, headers={'Content-Type': content_type})
303 return s3r

Callers

nothing calls this directly

Calls 4

make_auth_headerFunction · 0.85
readMethod · 0.80
formatMethod · 0.45

Tested by

no test coverage detected