我有一个本地托管的Flask服务器和一个小型React应用程序。我尝试使用FilePond作为图像上传的简单解决方案。FilePond负责将每个映像发送到服务器。在
所以我现在遇到的问题显然是后端代码。我把服务器设置成这样,per Flask's docsUPLOAD_FOLDER='/images'
ALLOWED_EXTENSIONS = set(['png', 'jpg', 'jpeg', 'gif'])
app = Flask(__name__)
app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER
def allowed_file(filename):
return '.' in filename and \
filename.rsplit('.', 1)[1].lower() in ALLOWED_EXTENSIONS
@app.route('/', methods=['GET', 'POST'])
def upload_file():
print(request.files)
if request.method == "POST":
# check if the post request has the file part
if 'file' not in request.files:
print('No file part')
return make_response("No File Part", 400)
file = request.files["file"]
# if user does not select file, browser also submit an empty part
# without filename
if file.filename == '':
print('No selected file')
return make_response("No Selected File", 400)
if file and allowed_file(file.filename):
filename = secure_filename(file.filename) # filenames can be dangerous!
file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename))
return make_response("Success", 201)
但是,当
^{pr2}$
语句在upload_file()函数的开头,似乎这是服务器正在接收的请求:ImmutableMultiDict([('images', )])
我不知道该怎么处理。我不知道“图像”是不是“文件”应该在哪里。我只是不太确定从这里到哪里去,或者如何处理接收到的数据。我不知道是什么,我从来没见过这种语法。在
有人能帮忙吗?在
谢谢你!在