Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def upload_file(f):
""" Upload file to Telegra.ph's servers. Returns a list of links.
Allowed only .jpg, .jpeg, .png, .gif and .mp4 files.
:param f: filename or file-like object.
:type f: file, str or list
"""
with FilesOpener(f) as files:
response = requests.post(
'https://telegra.ph/upload',
files=files
).json()
if isinstance(response, list):
error = response[0].get('error')
else:
error = response.get('error')
if error:
raise TelegraphException(error)
return [i['src'] for i in response]