这是前端文件上传的代码。
axios.post(
'http://localhost:3333/api/Containers/mycontainer/upload',
{
file: files[0]
},
{
headers: {
Accept: 'multipart/form-data'
}
}
);
当我在浏览器控制台中发布文件时,出现此消息
POST http://localhost:3333/api/Containers/mycontainer/upload net::ERR_EMPTY_RESPONSE
在服务器中出现此日志
Error: Request aborted
at IncomingMessage.<anonymous> (/Users/hayksafaryan/Projects/other/ev/node_modules/formidable/lib/incoming_form.js:122:19)
at IncomingMessage.emit (events.js:182:13)
at abortIncoming (_http_server.js:444:9)
at socketOnClose (_http_server.js:437:3)
at Socket.emit (events.js:187:15)
at TCP._handle.close (net.js:616:12)
Unhandled error for request POST /api/Containers/mycontainer/upload: Error: Request aborted
at IncomingMessage.<anonymous> (/Users/hayksafaryan/Projects/other/ev/node_modules/formidable/lib/incoming_form.js:122:19)
at IncomingMessage.emit (events.js:182:13)
at abortIncoming (_http_server.js:444:9)
at socketOnClose (_http_server.js:437:3)
at Socket.emit (events.js:187:15)
at TCP._handle.close (net.js:616:12)
在后端,我遵循了本指南 https://loopback.io/doc/en/lb2/Storage-component.html
这是数据源
"fileStorage": {
"name": "fileStorage",
"connector": "loopback-component-storage",
"provider": "filesystem",
"root": "./fileStorage",
"maxFileSize": "10485760"
}
使用回送3