I am working on a flask based UI and there I am downloading a text file using send_file function.
This is my directory setup:
/static
/design.css
/templates
/index.html
/upload.html
/engine.html
/output
/text_file.txt
/main.py
Below is the code:
@app.route('/download')
def download_file():
path = "output\\text_file.txt"
return send_file(path, as_attachment=True)
And below is related html button which is initiating the download:
<button>
<a href="{{ url_for('.download_file') }}" style="color: white; text-decoration: none;">Download Source Text
</a>
</button>
Now this function is directly downloading the file in downloads folder of my local C drive. But I want to get an option to select the location like below:
(image taken from google)
How can I achieve this?
CodePudding user response:
The path to save the downloaded file is decided by a browser and server-side application cannot change this--and this is a feature, not a bug.
You think about it--say a server application can pick a location to save a file, what if my website saves an exe file to your C:\Windows folder? The consequence is disastrous...
Some modern browsers allow users to set a default download path. If you discover that your file is saved to a folder, such as Downloads
, without asking you, most likely you have this browser feature enabled.