'flask send files from python via rest to frontend

I have a small python backend with an flash REST api. Now I want to send some data from Backend to Frontend. Any best practices for this?

Especially I have stl files.

I tried to base64 encode them like this:

    script_dir = os.path.dirname(__file__) #<-- absolute dir the script is in
    rel_path = "stls\\Charmander.stl"
    abs_file_path = os.path.join(script_dir, rel_path)

    f = open(abs_file_path, "r")

    base64_bytes = base64.b64encode(f.read())

but I got this error: UnicodeDecodeError: 'charmap' codec can't decode byte 0x8f in position 106: character maps to <undefined>



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source