代码之家  ›  专栏  ›  技术社区  ›  jonesy19

如何下载一个文件名。点前缀?

  •  1
  • jonesy19  · 技术社区  · 7 年前

    谢谢

    @app.route('/.blah.auth', methods=['GET'])
    def downloadBlahAuth(roleLevel = app.config["PAGE_ROLE_LEVELS"][".blah.auth"]):
      """
      filePath = os.path.join(app.config["DOWNLOADS_FOLDER"], ".blah.auth");
      theFile = open(filePath, "r")
      fileText = theFile.read()
      theFile.close()
    
      strIO = StringIO.StringIO()
      strIO.write(fileText)
      strIO.seek(0)
      return send_file(strIO, attachment_filename=".blah.auth", as_attachment=True)
      """
      fileName = ".blah.auth"
      return send_from_directory(directory=app.config["DOWNLOADS_FOLDER"], filename=fileName)
    
    0 回复  |  直到 7 年前