1 Star 0 Fork 0

ningbo/file-server

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
app.py 1.36 KB
一键复制 编辑 原始数据 按行查看 历史
from flask import request, Flask, send_from_directory, url_for, jsonify
import os
import datetime
basepath = r'F:\0.http'
app = Flask(__name__)
@app.route("/", methods=["GET"])
def index():
file_list = os.listdir(basepath)
text = ""
if len(file_list) != 0:
for i in file_list:
text = text + i + "\n"
else:
text = "root dir have not any file!\n"
return text
@app.route('/<path:filename>', methods=['GET'])
def download(filename):
file_list = os.listdir(basepath)
for file in file_list:
if filename in file:
return send_from_directory(basepath, file, as_attachment=True)
return "root dir have not file:{}\n".format(filename)
@app.route('/upload', methods=['POST'])
def upload_file():
f = request.files['file']
upload_path = os.path.join(basepath, f.filename)
f.save(upload_path)
url = url_for('upload_file', _external=True).replace(
"upload", "") + f.filename
return jsonify({'url': url})
@app.route('/getDate', methods=['POST', 'GET'])
def getDate():
return datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')
@app.route('/getUTCDate', methods=['POST', 'GET'])
def getUTCDate():
return datetime.datetime.utcnow().strftime('%Y-%m-%d %H:%M:%S')
if __name__ == '__main__':
app.run(host="0.0.0.0", port=80)
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/ningbocai/file-server.git
git@gitee.com:ningbocai/file-server.git
ningbocai
file-server
file-server
main

搜索帮助

0d507c66 1850385 C8b1a773 1850385