I am in the process of creating a RESTful API using the Python libraries flask-restful
and flask
. I have managed to get this working perfectly in the case of the functions that return only one image. Such as in the function example below
class GreyShift(Resource):
def get(self, path):
final_path = "Images/" + path
img_location = "temp/greyshift.jpg"
cv2.imwrite(img_location, cv2.imread(final_path, 0))
return send_file(img_location, mimetype='image/jpeg')
However, my issue is in the functions where i have to return multiple files in one return. Is there a function to do this in flask
? Or is there a better way to accomplish this task.
Update:
Eventually ended up using zipfile
library to zip the files together and return them in a single file in the response. As others have pointed out using flask at all to return files is sub-optimal due to it being single threaded. A much better implementation would be to upload the file to a file share service and return a URL link to the file. I did not however, implement this as this was just for a proof of concept application.