Skip to content

Instantly share code, notes, and snippets.

@BernardoGO
Created June 14, 2022 20:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save BernardoGO/6fcbab9350fb3eba357d2bb30058b261 to your computer and use it in GitHub Desktop.
Save BernardoGO/6fcbab9350fb3eba357d2bb30058b261 to your computer and use it in GitHub Desktop.
import base64
import json
import requests
URL = 'https://api.imgur.com/3/image'
AUTHORIZATION = 'Client-ID c9a6efb3d7932fd'
with open("download.png", 'rb') as f:
image = base64.b64encode(f.read())
def imgur(images):
session = requests.Session()
session.headers['Authorization'] = AUTHORIZATION
for image in images:
response = session.post(URL, data=image)
if response.status_code >= 400:
print ('Failed to upload image')
continue
url = response.json()['data']['link']
print(url)
imgur([image])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment