dutchcoders / transfer.sh

Easy and fast file sharing from the command-line.
https://github.com/dutchcoders/transfer.sh
MIT License
15.08k stars 1.54k forks source link

Using aiohttp #580

Closed syricium closed 4 months ago

syricium commented 9 months ago

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.

amayer5125 commented 7 months ago

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.