I am trying to send 2 pngs(or jpeg or any other format) images from my Flask server to my Reactjs front to display them there. I'm not sure how to encode this response though. The closest i've got is with people recommending to attach the images to a multipart form and send the form, but i can't quite figure out how to parse the form at the front since the response.data is a string.
I'm aware that this is likely not even the correct way to construct a multipart form on top of the it usually being used to send TO the server and not FROM, so i'll appreciate any corrections!
from flask import Flask, Response
from requests_toolbelt import MultipartEncoder
{...}
# getting the images
bytes_object_rest = do_plot(rest_coordinate_arrays, rest_vcg_arrays)
bytes_object_stress = do_plot(stress_coordinate_arrays, stress_vcg_arrays)
]
mpencoder = MultipartEncoder(
fields={'rest_graph': ('rest.png', bytes_object_rest, 'image/png'),
'stress_graph': ('stress.png', bytes_object_stress, 'image/png')},
)
return Response(mpencoder.to_string(), mimetype=mpencoder.content_type)
In the end, i'd like to know how to have a flask endpoint expose 2 .png plots to react and how to parse that response so i can render those 2 plots on the front. Thank you very much!
[]