문제

I have written a POST route in Express.js: /api/file/upload. This route needs two parameters to work - a "file" parameter with the posted file and an "apiKey" parameter, which is a string. To test it, I am trying to create a successful request in Fiddler2 with the following data:

Headers:

Content-Type: multipart/form-data; boundary=-------------------------acebdf13572468
User-Agent: Fiddler
Host: localhost:8000
Content-Length: 178037

Request Body:

---------------------------acebdf13572468
Content-Disposition: form-data; name="file"; filename="4Byl64P (1).jpg"
Content-Type: image/jpeg

<@INCLUDE *C:\Users\patrick\Pictures\4Byl64P (1).jpg*@>
---------------------------acebdf13572468--


---------------------------acebdf13572468
Content-Disposition: form-data; name="apiKey"
Content-Type: application/json

{
  "apiKey": "GKBG-QoNs-f74E-Z8Qn-zozm"
}
---------------------------acebdf13572468--

But when I try to log the parameters in Node.js, I get an empty object for request.body and undefined for request.files.

How do I successfully POST form data to Node.js using Fiddler2?

도움이 되었습니까?

해결책

Your body is malformed (premature ending boundary). It should probably look more like this:

---------------------------acebdf13572468
Content-Disposition: form-data; name="apiKey"
Content-Type: application/json

{
  "apiKey": "GKBG-QoNs-f74E-Z8Qn-zozm"
}
---------------------------acebdf13572468
Content-Disposition: form-data; name="file"; filename="4Byl64P (1).jpg"
Content-Type: image/jpeg

<@INCLUDE *C:\Users\patrick\Pictures\4Byl64P (1).jpg*@>
---------------------------acebdf13572468--
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top