I have two APIs written in Python with Flask. The first one sends a request to the second and is supposed to receive an image file (png). The file is sent from the second with send_file("example.png", mimetype='image/png').
How do I retrieve it from the response? I want to save it when it's received by the first API.
Right now I have a code that is sending a .csv file. On the receiving end it has the following code:
result_file_path = os.path.join(constants.RESULTS_PATH, f"{analysis_task.id}.csv")
with open(result_file_path, 'w', newline='') as result_file:
result_file.write(Response.text)
I tried doing something like this with the image, but it doesn't work. Response.text is just a unicode text, to the best of my understanding, so how do I access the image file sent? There's no such thing as Response.image. I also tried to use cv2.imwrite
on Response.text, but that doesn't work as well.
Plus, an additional question: In this example, the .text is read and then written into a file using Python's csv library (that is imported). So why did it have to be sent as .csv from the second API to begin with?