-
Notifications
You must be signed in to change notification settings - Fork 46
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 to upload files (images, etc.) #30
Comments
imgpath = upload.upload_file(files)[0]['src'] can write like this, bc upload_file() return a list of dicts with src key. (sorry, my english is poor. |
Is there a way to upload multiple photos at once? bro |
# Importing required package
from telegraph.aio import Telegraph
from pathlib import Path
import asyncio
# Declaring asynchronous function for using await
async def main():
# Creating new Telegraph object
telegraph = Telegraph()
# Creating new account
await telegraph.create_account("Test", author_name="Test")
# Upload images in directory.
image_dir = Path("~/Pictures/")
uploaded_files = ""
for path_object in image_dir.rglob("*"):
if path_object.is_file():
try:
file = await telegraph.upload_file(path_object)
uploaded_files += f'<img src={file[0]["src"]}>'
except:
print(f"Image {path_object} is probably too big")
# Creating new page
if uploaded_files != "":
new_page = await telegraph.create_page(
"Bulk",
html_content=uploaded_files
)
# Printing page url into console
print(new_page["url"])
# Running asynchronous function
asyncio.run(main()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
It's not an issue, I just want to share this code
The text was updated successfully, but these errors were encountered: