#!/usr/bin/env python3 #-*- coding:utf-8 -*- import os,sys from flask import Flask,render_template,request,send_file,send_from_directory app=Flask(__name__) BASE_PATH=os.path.dirname(os.path.abspath(__file__)) @app.route("/upload",methods=["POST"]) def upload_file(): try: f=request.files["file"] filename = os.path.join(BASE_PATH,"upload",f.filename) print(filename) f.save(filename) return "file upload successfully!" except Exception as e: return "failed!" @app.route("/download/<filename>",methods=["GET"]) def download_file(filename): dir = os.path.join(BASE_PATH,‘download‘) return send_from_directory(dir,filename,as_attachment=True) def mkdir(dirname): dir = os.path.join(BASE_PATH,dirname) if not os.path.exists(dir): os.makedirs(dir) if __name__ == "__main__": mkdir(‘download‘) mkdir(‘upload‘) app.run(host="0.0.0.0",port=8000,debug=False)
curl -F "file=@hello.txt" http://127.0.0.1:8000/upload
wget http://127.0.0.1:8000/download/test.csv
标签:shangdixinxi 上地信息