Using aiohttp #49

Closed
opened 2026-01-19 18:28:45 +00:00 by michael · 1 comment
Owner

Originally created by @7468656F on GitHub.

Does anyone know how to use aiohttp to put a file? I've been trying for way too long and every time I go to the page that it was supposedly uploaded to, it just gives me a 404 message. It works just fine when uploading through the website.

Originally created by @7468656F on GitHub. Does anyone know how to use aiohttp to put a file? I've been trying for way too long and every time I go to the page that it was supposedly uploaded to, it just gives me a 404 message. It works just fine when uploading through the website.
Author
Owner

@amayer5125 commented on GitHub:

I'm not familiar with aiohttp, but I got this example working pretty easily.

import aiohttp
import asyncio

async def main():
	async with aiohttp.ClientSession() as session:
		files = {"file": open("data.txt", "rb")}

		async with session.post("http://example.com/", data=files) as response:
			print(await response.text())

asyncio.run(main())

When I run it, it outputs the URL returned from transfer.sh. The documentation has more examples.

@amayer5125 commented on GitHub: I'm not familiar with [aiohttp](https://docs.aiohttp.org/en/stable/), but I got this example working pretty easily. ```python import aiohttp import asyncio async def main(): async with aiohttp.ClientSession() as session: files = {"file": open("data.txt", "rb")} async with session.post("http://example.com/", data=files) as response: print(await response.text()) asyncio.run(main()) ``` When I run it, it outputs the URL returned from transfer.sh. The [documentation](https://docs.aiohttp.org/en/stable/client_quickstart.html#post-a-multipart-encoded-file) has more examples.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: dutchcoders/transfer.sh#49