python3 flask 编写上传文件接口

【自取】最近整理的,有需要可以领取学习:

依赖环境:python3

依赖包:flask,pyOpenSSL(pip install flask pyOpenSSL)

python;gutter:true;</p> <h1>coding=utf-8</h1> <p>import os from flask import Flask, redirect, url_for, request, render_template, send_from_directory import time app = Flask(<strong>name</strong>) BASE_PATH = '/tmp/tmp_file/'</p> <p>@app.route("/upload",methods=["POST"]) def upload_file(): try: f=request.files["file"]</p> <pre><code> filename = os.path.join(BASE_PATH,"",f.filename) f.save(filename) print("{0} file upload succcessfully!".format(filename)) time.sleep(1) return "file upload successfully!" except Exception as e: return e </code></pre> <p>if <strong>name</strong> == '<strong>main</strong>': app.run(host="0.0.0.0",port="5555",debug=False,ssl_context="adhoc")

Original: https://www.cnblogs.com/royfans/p/16106060.html
Author: RoyFans
Title: python3 flask 编写上传文件接口

原创文章受到原创版权保护。转载请注明出处:https://www.johngo689.com/15707/

转载文章受原作者版权保护。转载请注明原作者出处!

(0)

大家都在看

发表回复

登录后才能评论
免费咨询
免费咨询
扫码关注
扫码关注
联系站长

站长Johngo!

大数据和算法重度研究者!

持续产出大数据、算法、LeetCode干货,以及业界好资源!

2022012703491714

微信来撩,免费咨询:xiaozhu_tec

分享本页
返回顶部