No content-length while Sending File via REST call in mendix

0
Hi everyone, I’m working on a mendix app where we are trying to send a file document to an external service. I use form-data in request body.  However, I got an error message (empty media data) from the external service. I checked the HTTP resquest sent from mendix, it shows as below. Request content for POST request to https://qyapi.weixin.qq.com/cgi-bin/media/upload?access_token=xxxxxx&type=file HTTP/1.1 Content-Type: multipart/form-data; boundary="----=_Part_8_1375038341.1638245570208" ------=_Part_8_1375038341.1638245570208 Content-Type: application/octet-stream Content-Disposition: form-data; name="media";filename="wework.txt.txt"; filelength=6 mytext ------=_Part_8_1375038341.1638245570208-- Everything seems ok except that there’s no Content-Length in the request header. I tested in Postman, got same error while send file without ‘content-length’. I tried to calculate and add content-length to request header, but got another error from mendix.   Can someone help me how can I send a file with form-data body by Rest call?
asked
2 answers
0

Hi Lynn,

Which HTTP headers do you send? (apart from the default content-types that Mendix adds automatically)

For example: do you have a ‘Accept:application/json’ header set for the response from the server?

answered
0
Request content for POST request to https://qyapi.weixin.qq.com/cgi-bin/media/upload?access_token=xxx&type=file HTTP/1.1
Accept: application/json
Content-Type: multipart/form-data; boundary="----=_Part_2_1709568546.1638275702857"

------=_Part_2_1709568546.1638275702857
Content-Type: application/octet-stream
Content-Disposition: form-data; name="media"; filename="wework.txt.txt"

mytext
------=_Part_2_1709568546.1638275702857--
Response content for POST request to https://qyapi.weixin.qq.com/cgi-bin/media/upload?access_token=xxx&type=file
HTTP/1.1 200 OK
Server: nginx
Date: Tue, 30 Nov 2021 12:35:03 GMT
Content-Type: application/json; charset=UTF-8
Content-Length: 171
Connection: keep-alive
Error-Code: 44001
Error-Msg: empty media data, hint: [1638275703408543409302529], from ip: 20.197.0.110, more info at https://open.work.weixin.qq.com/devtool/query?e=44001

{"errcode":44001,"errmsg":"empty media data, hint: [1638275703408543409302529], from ip: 20.197.0.110, more info at https://open.work.weixin.qq.com/devtool/query?e=44001"}

 

answered