在Node JavaScript中上传文件时出错-您是否忘记了使用body-parser中间件?

时间:2018-09-13 11:46:20

标签: node.js curl file-upload

我尝试通过节点JavaScript中的curl命令上传文件。

这是我的curl命令:

curl --request POST --url http://localhost:3000/api --header 'accept: application/json' --header 'accept-encoding: gzip, deflate, br' --header 'accept-language: en-GB,en-US;q=0.9,en;q=0.8' --header 'authorization: Bearer Token' --header 'cache-control: no-cache' --header 'connection: keep-alive' --header 'origin: http://localhost:3000' --header 'postman-token: 06bd88f3-6928-d648-34a0-65168f60b5f0' --header 'referer: http://localhost:3000/' --header 'user-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36' \ -F '{"query":"mutation{\n  sendMessage(input:{toUserId:\"4789838293237760\",message:\"Hello, Are you there?\"})\n  {\n  id\n  message\n    modifiedOn\n    linkedUsers\n    {\n      id\n role\n firstName\n lastName \n   }\n    \n  }\n}","variables":{ "file": {null} }}' \ -F map='{ "0": ["variables.files.0"]}' \ -F 0=@
/Users/example/Desktop/DSC_0339.JPG

我遇到以下错误

POST body missing. Did you forget use body-parser middleware?curl: (6) Could not resolve host:  -F
curl: (3) [globbing] nested brace in column 19
curl: (6) Could not resolve host:  -F
curl: (3) [globbing] nested brace in column 12
curl: (6) Could not resolve host:  -F
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>400 Bad Request</title>
</head><body>
<h1>Bad Request</h1>
<p>Your browser sent a request that this server could not understand.<br />
</p>
<p>Additionally, a 400 Bad Request
error was encountered while trying to use an ErrorDocument to handle the request.</p>
</body></html>

0 个答案:

没有答案