telegraph icon indicating copy to clipboard operation
telegraph copied to clipboard

How to upload files (images, etc.)

Open vovkapultik opened this issue 4 years ago • 3 comments

It's not an issue, I just want to share this code

from telegraph import Telegraph, upload

telegraph = Telegraph()
telegraph.create_account(short_name='LetsTry')

def post(title, content):
	response = telegraph.create_page(title,
									 html_content = content)
	return 'https://telegra.ph/{}'.format(response['path'])

files = '/Users/vovkapultik/Downloads/52920087_159420908268041_6560105268061929472_n.jpg'

imgpath = upload.upload_file(files)

print(imgpath)

#['/file/02a1613fc106b225b2b74.jpg']

postlink = post('Title', '<img src="/file/02a1613fc106b225b2b74.jpg">')

print(postlink)

vovkapultik avatar Sep 05 '20 16:09 vovkapultik

imgpath = upload.upload_file(files)[0]['src'] postlink = post('Title', imgpath)

can write like this, bc upload_file() return a list of dicts with src key. (sorry, my english is poor.

MuuJian avatar Jul 07 '22 22:07 MuuJian

Is there a way to upload multiple photos at once? bro

Suharaz avatar Dec 09 '22 16:12 Suharaz