An issue that occurs when you download a file by using flask that a file is not downloaded

Source: Internet
Author: User

From flask import send_from_directory@app.route ('/uploads/<filename> ') def uploaded_ File (filename):     return send_from_directory (app.config[' Upload_folder '],                                 filename)                                  genericpath.py  If the system installs this component: It will replace the system's own path function, resulting in Path has failed. The file will not be found in the end. The code has only such a short few words. This os.path.isfile is going to be a problem. So, put in the uploaded_file to complete this action, you can "" "Filename = safe_join (directory, filename) if not  Os.path.isfile (filename):     raise notfound () options.setdefault (' conditional ',  True) Return send_file (filename, **options)               The final code looks like this: #filename  = flask.safe_join (Upload_folder,  filename) Print (Flask.safe_join (upload_folders,secure_filename (filename)) print (os.path.isfile (filename)) Return flask.send_file (Flask.safe_join (upload_folders,secure_filename (filename)), as_attachment=true)

From the perspective of the phenomenon, It seems that genericpath.py the python itself with the path of the class rewrite, resulting in all the operation of the path to the Genericpath, this class of processing and the system comes with some of the same, so it will lead to the same method return value completely different situation,

For example: Os.path.isfile This method executes, the same file will produce different results.

An issue that occurs when you download a file by using flask that a file is not downloaded

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.