Skip to content

Instantly share code, notes, and snippets.

@peacememories
Created February 29, 2024 21:59
Show Gist options
  • Save peacememories/0a58d5fb324eec09614b097cc0692aa1 to your computer and use it in GitHub Desktop.
Save peacememories/0a58d5fb324eec09614b097cc0692aa1 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python3
from requests import post
from flask import Flask, request
from threading import Thread
from os import urandom
from io import BytesIO
import time
SIZE = 3000 # Size in bytes
app = Flask(__name__)
app.debug = True
destination = BytesIO()
@app.post("/")
def upload_file():
print("Got Pinged")
if "file" not in request.files:
return '', 400
file = request.files["file"]
file.save(destination)
return ''
thread = Thread(target=app.run, kwargs={"use_reloader": False, "port": 8880})
thread.daemon = True
thread.start()
content = urandom(SIZE)
file = BytesIO(content)
response = post("http://localhost:8880/", files={
"file": file
})
assert response.status_code == 200, f"Expected 200 OK, got {response.status_code}"
assert content == destination.getvalue()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment