Corrupted file if it is downloaded several times.

I have a Flask application that works for Apache as a reverse proxy server, here is the route to the url for downloading zip files:

@application.route('/files/<path:name>')
def files(name=None):
    if "UPLOAD_DIR" not in os.environ:
        return "upload disabled", httplib.NOT_FOUND
    if ".." in name:
        return "no no", httplib.BAD_REQUEST
    _dir = os.path.dirname(name)
    name = os.path.basename(name)
    path = os.path.join(os.environ['UPLOAD_DIR'], _dir)
    return send_from_directory(path, name, as_attachment=True)

If I download the file several times, the downloaded zip file will be damaged and I cannot open it.

My configuration for shooting:

gunicorn -b localhost:5000 -t 300 -w 7 --worker-connections 7 application:application

Edit: at first I had too many damaged files, when I downloaded the same file several times, I had one worker, but as soon as I added that 6 others (only 7 employees), everything got better, but some files zip was still corrupted if downloaded several times.

+4
source share

All Articles