Search code examples
pythonimgur

Uploading image using pyimgur to imgur, using images link


I was interested in uploading images to the imgur API. In the docs to upload the image

import pyimgur

CLIENT_ID = "Your_applications_client_id"
PATH = "A Filepath to an image on your computer"

im = pyimgur.Imgur(CLIENT_ID)
uploaded_image = im.upload_image(PATH, title="Uploaded with PyImgur")
print(uploaded_image.title)
print(uploaded_image.date)
print(uploaded_image.url)
print(uploaded_image.link)

I am curious if someone knows how to instead of using a path( have the image saved locally), just have a link to a image to upload to imgur. I feel like it exists due to the fact with the GUI website you can enter a picture link and can then upload.

Thank you for the help.


Solution

  • The Imgur.upload_image() method takes a url argument, simply pass it a URL of an image to add:

    uploaded_image = im.upload_image(url=URL_OF_IMAGE, title="Uploaded with PyImgur")
    

    You must either provide a path or a URL, but not both.

    See the upload_image() documentation for all arguments it accepts:

    Upload the image at either path or url.

    • path – The path to the image you want to upload.
    • url – The url to the image you want to upload.