0

I'm using the pyimgur module to upload to imgur. It works fine with local files but is there a way to upload to imgur using a image URL(jpg,png). I looked around but couldn't find a solid answer. Current code I'm using is this(for local images),

import pyimgur

CLIENT_ID = "<id>"
im = pyimgur.Imgur(CLIENT_ID)
image = '<local-image>'
uploaded_image = im.upload_image(image, title='title')

Thank you

  • You could first [download the file from the URL](https://stackoverflow.com/questions/22676/how-to-download-a-file-over-http) then use your code to re-upload it once it is local on your machine – Cory Kramer Feb 11 '22 at 19:14
  • @CoryKramer True, but isn't there a way to do it without downloading and uploading. – Dulan Pabasara Feb 11 '22 at 19:20
  • 1
    Simple, no you can't. If you're trying to repost or share an existing upload, then that's reposting/sharing. They don't provided that functonality, so you can't. Same way all email providers require you to either upload a file or use their service's cloud storage to attach a file you have access to - but from nowhere else. Voting to close. – aneroid Feb 11 '22 at 19:32

1 Answers1

3
import requests

img_url = 'https://my/image/url.jpg'

api = 'https://api.imgur.com/3/image'

params = dict(
    client_id='546c25a59c58ad7'
)

files = dict(
    image=(None, img_url),
    name=(None, ''),
    type=(None, 'URL'),
)

r = requests.post(api, files=files, params=params)