import requests import os import base64 import argparse def read_file(path: str) -> bytes: with open(path, "rb") as fp: return fp.read() def upload_map(map_path): map_filename = os.path.basename(map_path) content = read_file(map_path) b64_content = base64.b64encode(content).decode("utf8") r = requests.post("http://127.0.0.1:8000/maps", json={"name": map_filename, "b64_data": b64_content}) print(r.json()) if __name__ == '__main__': parser = argparse.ArgumentParser() parser.add_argument("path") args = parser.parse_args() upload_map(args.path)