前端:
<html>
<head>
<title>File Upload</title>
</head>
<body>
<form action="http://192.168.3.33:8087/uploadVPNFile" method="POST" enctype="multipart/form-data">
<input type="file" name="file"/>
<input type="submit" />
</form>
</body>
</html>
必须有 enctype="multipart/form-data"
和 <input type="file" name="file"/>
后端:
@app.route('/uploadVPNFile', methods=['POST'])
def upload_vpn_file():
print(121212)
if 'file' not in request.files:
print('No file part')
return "未上传文件"
file = request.files['file']
user_name = file.filename[:-5]
upload_path = "/home/ovpnfolder/" + str(file.filename)
file.save(upload_path)
官方实例:
https://dormousehole.readthedocs.io/en/latest/patterns/fileuploads.html
|