Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to POST image in imgbb.com via python?

Tags:

python

curl --location --request POST "https://api.imgbb.com/1/upload?key=YOUR_CLIENT_API_KEY" --form "image=R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7"

How to post an image in imgbb? I am beginner. I can not post any image.

url = 'https://api.imgbb.com/1/upload'
key = '232565fc1a4f0d24578d9aeadc0b43ab'
res = requests.post(
    url, 
    data = {
        'key': key, 
        'image':b64encode(open('a.png', 'rb').read()),
        'name': 'a.png',
    }
)
like image 217
Ahmed Nazir Avatar asked Oct 26 '25 03:10

Ahmed Nazir


1 Answers

That is what worked for me.

import base64
import requests

with open("fig1.png", "rb") as file:
    url = "https://api.imgbb.com/1/upload"
    payload = {
        "key": key_imgbb,
        "image": base64.b64encode(file.read()),
    }
    res = requests.post(url, payload)
like image 91
benhofmann Avatar answered Oct 29 '25 09:10

benhofmann



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!