RESTEasy客户端API文件上传到python/Flas

2024-06-01 13:36:55 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图使用RESTEasy客户端api将一个文件上传到python Flask REST服务,但最终得到了一个http400错误的请求响应。你知道吗

Java客户端:

MultipartFormDataOutput mpfdo = new MultipartFormDataOutput();
mpfdo.addFormData("video", new FileInputStream(new File('file')), MediaType.APPLICATION_OCTET_STREAM_TYPE);
Client client = ClientBuilder.newClient();
WebTarget target = client.target("localhost:5000").path("/video/detect");
Response r = target.request().post(Entity.entity(mpfdo, MediaType.MULTIPART_FORM_DATA_TYPE));

python服务:

@app.route('/video/detect', methods=["POST"])
def VideoDetectFrame():
   f = request.files['video']
   #returns 400 response

数据似乎在request.form中,而不是在request.files中。当使用Postman发送文件时,它可以正常工作。你知道吗


Tags: 文件clientapi客户端targetnewrequestvideo