Closed f126ck closed 7 years ago
It's not possible to upload photos/videos via API, but you can use this code
import requests
with open('/Users/python273/Desktop/123345.jpeg', 'rb') as f:
print(
requests.post(
'http://telegra.ph/upload',
files={'file': ('file', f, 'image/jpeg')} # image/gif, image/jpeg, image/jpg, image/png, video/mp4
).json()
)
Thank you very very very much :)
how to use this in php?
import requests
with open('/Users/python273/Desktop/123345.jpeg', 'rb') as f:
print(
requests.post(
'http://telegra.ph/upload',
files={'file': ('file', f, 'image/jpeg')} # image/gif, image/jpeg, image/jpg, image/png, video/mp4
).json()
)
@f126ck Could you, please, share your code? What should I put instead of 'file'? - I've tried every possible combination of my file name and it doesn't work..
@python273 Could you tell me, please, what would I change in order to make the post with picture? I used your code for example. I will be waiting for your response. Thank you!
from telegraph import Telegraph
telegraph = Telegraph()
telegraph.create_account(short_name='1337')
response = telegraph.create_page(
'Hey',
html_content='<p>Hello, world!</p>'
)
with open('/Users/deantipin/picture.png', 'rb') as f:
print(
requests.post(
'http://telegra.ph/upload',
files={'Hey': ('Hey', f, 'image/png')} # image/gif, image/jpeg, image/jpg, image/png, video/mp4
).json()
)
print('http://telegra.ph/{}'.format(response['path']))
@deantipin maybe i'm late, but it should work
from telegraph import Telegraph
telegraph = Telegraph()
telegraph.create_account(short_name='1337')
with open('/Users/deantipin/picture.png', 'rb') as f:
path = requests.post(
'https://telegra.ph/upload', files={'file':
('file', f,
'image/jpeg')}).json()[0]['src']
response = telegraph.create_page(
'Hey',
html_content="<p>Hello, world!</p> \
<img src='{}'/>".format(path),
)
print('http://telegra.ph/{}'.format(response['path']))
Hello! Guys its possible posting to telegra.ph but from url via node js? I need posting to telegraph picture not form hard disk, from url only Thank you
@greatspoke you can download the picture and upload to telegraph
Hey guys
Just in case telegraph has suddenly started returning "error: no files passed": it looks like telegraph has moved to https (finally!), so http://telegra.ph/upload
from the examples above should be changed to https://telegra.ph/upload
I mean use with https://www.npmjs.com/package/telegraph-node try
ph.createPage(token, 'bot_greatspoke', ['[url]https://goo.gl/FHcL485[/url]'], { return_content: true }).then((result) => { console.log(result) })
But not work(((
Using http I'm getting: response [200] with {"error":"No files passed"}
Using https I'm getting: response [500]
What I'm doing wrong?
It's not possible to upload photos/videos via API, but you can use this code
import requests with open('/Users/python273/Desktop/123345.jpeg', 'rb') as f: print( requests.post( 'http://telegra.ph/upload', files={'file': ('file', f, 'image/jpeg')} # image/gif, image/jpeg, image/jpg, image/png, video/mp4 ).json() )
Hello, @python273! Have been trying to upload an image both via requests.post()
(as featured in your example) and telegraph.upload.upload_file(f)
from your library, but I keep always getting the following error:
SSLError: HTTPSConnectionPool(host='telegra.ph', port=443): Max retries exceeded with url: /upload (Caused by SSLError(SSLError("bad handshake: SysCallError(10054, 'WSAECONNRESET')")))
No googling of the issue helped so far. :( Please, can anything be done about it ?
Seems like /upload
is not part of the API, so not really sure about 500 and other errors
SSLError: HTTPSConnectionPool(host='telegra.ph', port=443): Max retries exceeded with url: /upload (Caused by SSLError(SSLError("bad handshake: SysCallError(10054, 'WSAECONNRESET')")))
Maybe telegra.ph
is blocked for you, so you need to use proxy
I face this issue: https://github.com/python273/telegraph/issues/36
Does anyone here face this? I do the same code that mentions this issue, it works fine for image but error for video/mp4.
@GooDeeJaY Maybe telegra.ph is blocked for you Use te.legra.ph in this case
Noob here. I wanted to know if it was possible to make a telegraph article including photos/videos which I have got on my hard disk.
How can I upload them and show in the article?
Thanks