remotes/1693045480750635534/spooky-22
Aevann1 2021-07-22 23:03:27 +02:00
parent 0fda1a9125
commit 3bfedc6e71
1 changed files with 13 additions and 0 deletions

View File

@ -51,6 +51,7 @@ def upload_file(name, file, resize=None):
if resize:
tempname = name.replace("/", "_")
print(type(file))
file.save(tempname)
if tempname.split('.')[-1] in ['jpg', 'jpeg']:
@ -63,15 +64,24 @@ def upload_file(name, file, resize=None):
req = requests.post('https://api.imgur.com/3/upload.json', headers = {"Authorization": f"Client-ID {imgurkey}"}, data = {'image': base64.b64encode(img.getvalue())})
try: resp = req.json()['data']
except Exception as e:
print(e)
print(req)
print(req.text)
return
remove(tempname)
else:
req = requests.post('https://api.imgur.com/3/upload.json', headers = {"Authorization": f"Client-ID {imgurkey}"}, data = {'image': base64.b64encode(file.read())})
try: resp = req.json()['data']
except Exception as e:
print(e)
print(req)
print(req.text)
return
try: url = resp['link'].replace(".png", "_d.png").replace(".jpg", "_d.jpg").replace(".jpeg", "_d.jpeg") + "?maxwidth=9999"
except Exception as e:
print(e)
print(req)
print(req.text)
return
new_image = Image(
@ -100,6 +110,9 @@ def upload_from_file(name, filename, resize=None):
remove(filename)
url = resp['link'].replace(".png", "_d.png").replace(".jpg", "_d.jpg").replace(".jpeg", "_d.jpeg") + "?maxwidth=9999"
except Exception as e:
print(e)
print(req)
print(req.text)
return
new_image = Image(