Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How can I upload images to telegraph via this library? #3

Closed
f126ck opened this issue Jan 16, 2017 · 19 comments
Closed

How can I upload images to telegraph via this library? #3

f126ck opened this issue Jan 16, 2017 · 19 comments

Comments

@f126ck
Copy link

f126ck commented Jan 16, 2017

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

@python273
Copy link
Owner

python273 commented Jan 16, 2017

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()
    )

@f126ck
Copy link
Author

f126ck commented Jan 16, 2017

Thank you very very very much :)

@mieburungdara
Copy link

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()
    )

@deantipin
Copy link

@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..

@deantipin
Copy link

deantipin commented Jan 15, 2018

@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']))

@n0execution
Copy link

n0execution commented Feb 19, 2018

@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']))

@greatspoke
Copy link

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

@python273
Copy link
Owner

@greatspoke you can download the picture and upload to telegraph

@apcel
Copy link

apcel commented Aug 19, 2018

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

@greatspoke
Copy link

greatspoke commented Sep 3, 2018

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(((

@jzr-supove
Copy link

Using http I'm getting: response [200] with {"error":"No files passed"}
Using https I'm getting: response [500]

What I'm doing wrong?

@macsunmood
Copy link

macsunmood commented Feb 9, 2020

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 ?

@python273
Copy link
Owner

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

@giangdinh
Copy link

I face this issue: #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.

@shizomontazh
Copy link

@goodeejay
Maybe telegra.ph is blocked for you
Use te.legra.ph in this case

@227234
Copy link

227234 commented Dec 20, 2022

#3 (comment)

@227234
Copy link

227234 commented Dec 20, 2022

#3 (comment)

@227234
Copy link

227234 commented Dec 20, 2022

#3 (comment)

@Maniac1488ss
Copy link

#53

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests