verbanote-client/verbanote_client/network_functions.py

17 lines
533 B
Python
Raw Normal View History

2023-08-25 21:25:59 +00:00
import requests
from pathlib import Path
from rich.console import Console
console = Console()
# TODO switch server component to be able to use S3 storage options
def _upload_to_oxo(file: Path, url: str = "https://0x0.st", expires: int = 2) -> str:
resp = requests.post(
url=url,
files={"file": open(file, "rb"), "expires": str(expires)},
)
if not resp.ok:
raise requests.exceptions.HTTPError()
console.log(f"Uploaded file {file} to {str(resp.content)}")
return str(resp.content).strip()