0

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>

OneCricketeer
  • 179,855
  • 19
  • 132
  • 245
Felix
  • 5,452
  • 12
  • 68
  • 163
  • Does this answer your question? [UnicodeDecodeError: 'charmap' codec can't decode byte X in position Y: character maps to ](https://stackoverflow.com/questions/9233027/unicodedecodeerror-charmap-codec-cant-decode-byte-x-in-position-y-character) – mcsoini Mar 06 '22 at 14:05
  • No, now I got this error: `UnicodeDecodeError: 'utf-8' codec can't decode byte 0xaf in position 84: invalid start byte` – Felix Mar 06 '22 at 14:08
  • You don't need base64 strings to return plaintext from an HTTP endpoint – OneCricketeer Mar 06 '22 at 14:49
  • so your advice is read the file und send the plain text file to frontend? – Felix Mar 06 '22 at 14:51

0 Answers0