mercredi 2 octobre 2019

Downloading files from a flask server

I created a simple web application where the user upload some file, a utility transform it and saves the files in the same directory where the original file was uploaded. Now I want to download the transformed file but I am getting errors.

These are my upload and download functions:

@app.route('/uploads/<filename>')
def uploaded_file(filename):
    return send_from_directory(app.config['UPLOAD_FOLDER'],
                               filename)


@app.route('/download/<filename>', methods=["POST"])
def download_file(filename):
    result = send_from_directory(app.config['UPLOAD_FOLDER'],
                               filename)
    response = make_response(result)
    response.headers["Content-Disposition"] = "attachment"; filename
    return response 

And this is the error I am getting when I click on the file links displayed:

The requested URL was not found on the server. If you entered the URL manually please check your spelling and try again.

More info: The files are uploaded to the data folder on the server

mywebapp
   --app.py
   --wsgi.py
   --data/
   --config.py



Aucun commentaire:

Enregistrer un commentaire