在同一个 Flask 请求中上传文件和一个字符串

Upload Files and a String in same Flask Request

我想使用 flask 上传文件和包含电子邮件地址的单独字符串。

我可以上传文件并将电子邮件地址存储在服务器上,但我想从客户端上传任何电子邮件地址

test_files = {('dicom', open("Pre_1", "rb")),
              ('dicom', open("Pre_2", "rb")),
              ('dicom', open("Post_1", "rb")),
              ('dicom', open("Post_2", "rb"))}
response = requests.post("MyWebsite.com", files = test_files)

适合我。但是我不确定如何将 email = "RecipientEmail@gmail.com" 添加到上传请求?

这是我在服务器端的。它获取文件并将它们保存到上传文件夹

@app.route("/upload", methods=["POST"])
def upload():
    uploaded_files = flask.request.files.getlist("dicom")
    print(uploaded_files, file=sys.stderr)
    for file in uploaded_files:
            filename = secure_filename(file.filename)
            file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename))

这很可能是我的错误代码,但我已经设置好让服务器在上传图像后开始处理图像。所以我还想在同一请求中上传收件人电子邮件地址。任何帮助将不胜感激!

客户

test_files = {('dicom', open("Pre_1", "rb")),
              ('dicom', open("Pre_2", "rb")),
              ('dicom', open("Post_1", "rb")),
              ('dicom', open("Post_2", "rb"))}
payload = {'email': 'myemail'}
response = requests.post("mywebsite", files = test_files, data = payload)

服务器

@app.route("/upload", methods=["POST"])
def upload():
    uploaded_files = flask.request.files.getlist("dicom")
    payload = request.form['email']

现在效果很好