Could not load file using jar with actual name

I am trying to upload a file using a jar. my code is as follows

@app.route('/Download')
def Down():
    rpm = request.args.get('rpm')
    root = '/home/rpmbuild/RPMS/'
    return send_from_directory(root,rpm)

The file name is passed in the URL. when i hit the url i can upload the file but the file name is always Download. I need this to be the actual file name. I also tried send_file(), but it also loads it with a name Download.

+4
source share
1 answer

The "options" send_from_directoryare the same as sendfile:

flask.send_file(filename_or_fp, mimetype=None, as_attachment=False,
                attachment_filename=None, add_etags=True,
                cache_timeout=None, conditional=False,
                last_modified=None)

So you should call it:

@app.route('/Download')
def Down():
    rpm = request.args.get('rpm')
    root = '/home/rpmbuild/RPMS/'
    return send_from_directory(root,rpm,attachment_filename='foo.ext')

, , 'foo.ext' , . , as_attachment True.

, os.path.basename(..) :

import os

@app.route('/Download')
def Down():
    rpm = request.args.get('rpm')
    root = '/home/rpmbuild/RPMS/'
    return send_from_directory(root,rpm,as_attachment=True,
                               attachment_filename=os.path.basename(rpm))
+3

Source: https://habr.com/ru/post/1673402/


All Articles