我正在運行端口3000
燒瓶服務器,端點:3000/upload
接受POST請求。但是,文件上傳部分不起作用。python燒瓶文件上傳失敗默默
@app.route('/upload', methods=['POST'])
def post_upload():
print ("test")
if request.method == 'POST':
print ("test2")
zfile = request.files['file']
if zfile:
print("test3")
filename = secure_filename(zfile.filename)
zfile.save(os.path.join(app.config['UPLOAD_FOLDER'],filename))
return "success"
else:
print ("test4")
return "fail"
return 'blah'
我發送具有形狀數據的POST key
等於file
和value
是PNG圖像。客戶得到的迴應是:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<title>400 Bad Request</title>
<h1>Bad Request</h1>
<p>The browser (or proxy) sent a request that this server could not understand.</p>
服務器上的打印輸出:
* Running on http://0.0.0.0:3000/ (Press CTRL+C to quit)
test
test2
104.148.224.253 - - [05/Aug/2017 19:30:04] "POST /upload HTTP/1.1" 400 -
爲什麼zfile = request.files['file']
後默默地失敗?
我先試了一下。我得到一個輸出說'沒有文件部分'。我使用POSTMAN,其中'key' ='file'和'value'是一個PNG圖像。 – bee