依赖环境: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/
转载文章受原作者版权保护。转载请注明原作者出处!