<div dir="ltr"><span style="font-family:arial,sans-serif;font-size:12.8px">Hi,</span><div style="font-family:arial,sans-serif;font-size:12.8px"><br></div><div style="font-family:arial,sans-serif;font-size:12.8px">  I have an application that allows users to upload files. I agonized over where to actually store these files, but in the end, since I wanted to keep some form of file history, and make things easy on myself for backups and things, I went with keeping everything in the Database.</div><div style="font-family:arial,sans-serif;font-size:12.8px"><br></div><div style="font-family:arial,sans-serif;font-size:12.8px">I have a route that looks something like this (alright, exactly like this):</div><div style="font-family:arial,sans-serif;font-size:12.8px"><br></div><div style="font-family:arial,sans-serif;font-size:12.8px"><div>mod.route('/resource/<int:resource_id>/<filename>', methods=['GET'])</div><div>def download_resource(resource_id, filename):</div><div>    ### HACK ALERT! WHOOP WHOOP WHOOP ###</div><div>    if 'If-Modified-Since' in request.headers:</div><div>        return Response(status=304)</div><div>    resource = model.lesson.get_lesson_resource(resource_id)</div><div>    </div><div>    if resource:</div><div>        r = Response(resource['file_data'], mimetype=resource['mime_type'])</div><div>        r.headers.add('Last-Modified', resource['timestamp'].strftime("%a, %d %b %Y %H:%M:%S GMT"))</div><div>        return r</div><div>    else:</div><div>        abort(404)</div></div><div style="font-family:arial,sans-serif;font-size:12.8px"><br></div><div style="font-family:arial,sans-serif;font-size:12.8px">it's a little bit hacky, but overall it does what I want. model.get_lesson_resource(resource_id) returns the blob from the database, I then build a Response object from that and return it.</div><div style="font-family:arial,sans-serif;font-size:12.8px"><br></div><div style="font-family:arial,sans-serif;font-size:12.8px">It is however REALLY REALLY slow at downloading the file - I can put a big file in the application's 'static' directory and Flask can send it down at my full network bandwith.</div><div style="font-family:arial,sans-serif;font-size:12.8px"><br></div><div style="font-family:arial,sans-serif;font-size:12.8px">If I attempt to download a large file from the route above it slows to < 2k/s.</div><div style="font-family:arial,sans-serif;font-size:12.8px"><br></div><div style="font-family:arial,sans-serif;font-size:12.8px">I don't understand why it's slow - it's not the database, because the blob has been pulled out from there before the Response can be returned. I've clearly done something heinous here but I can't see what it is - is there a better way to send the file back to the client?</div><div style="font-family:arial,sans-serif;font-size:12.8px"><br></div><div style="font-family:arial,sans-serif;font-size:12.8px">Thanks very much</div><div style="font-family:arial,sans-serif;font-size:12.8px">-Mike</div></div>