我正在尝试上传一个大约1.62MB的图像到一个使用flask编写的端点。这个请求.files对象始终为空。我已经检查了以下问题,但没有运气:
这是我的服务器:from flask import Flask, request, jsonify, render_template
import sys
app = Flask(__name__)
app.config['UPLOAD_FOLDER'] = r"C:\Temp"
app.debug = True
@app.route("/demo-upload", methods=["GET", "POST"])
def ProcessImage():
if request.method == "POST":
print(request.files)
try:
if 'file' in request.files:
with open("test-upload.png", "wb") as iFile:
print(request['file'])
iFile.write(request.files['file'])
except Exception as e:
print(e)
return jsonify("Ok")
@app.route("/", methods=["GET"])
def DemoIndexPage():
return render_template("index.html")
if __name__ == "__main__":
app.run()
我的委托人:
^{pr2}$
在我看来,一切都很干净,我不知道哪里出了问题。请求对象中的files属性始终为空。我还尝试了postman使用post请求,格式为data key=file和value=uploada file,头content type=“multipart/form data”。感谢任何帮助,谢谢!在