因此,我使用axios post请求从react向flask发送了一个图像,该图像采用formdata格式
const response = await axios({
method: "POST",
url: "http://127.0.0.1:5000/upload",
headers: { "content-type": "multipart/form-data" },
data: filou,
在 flask 回来,我收到图像,存储它,然后作为一个响应发送另一个图像
@app.route('/upload', methods=['POST'])
@cross_origin()
def fileUpload():
print("hello")
print(request.files)
# check if the post request has the file part
if 'file' not in request.files:
print("no file")
flash('No file part')
return "redirect(request.url)"
file = request.files['file']
# If the user does not select a file, the browser submits an
# empty file without a filename.
if file.filename == '':
print("no selected file")
flash('No selected file')
return redirect(request.url)
if file and allowed_file(file.filename):
print("\n YYYYYYYYYYYYYYYYYYYEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEYYYY \n")
print(file.filename)
filename = secure_filename(file.filename)
file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename))
# print(os.path.join(app.config['UPLOAD_FOLDER'], filename))
new_filename = app.config['UPLOAD_FOLDER']
print(new_filename)
return send_file(f"output/final_output/panda.jpg")
当我收到图像,我得到它像这样
enter image description here
但是我不能在react中显示它,我不知道如何做(我尝试了许多技术,blob,createObjectURL ...等等)
一个二个一个一个
如果有人能帮忙。
1条答案
按热度按时间dzhpxtsq1#
就像Unmitigated说的...