Error: Unexpected end of multipart data
at C:\Users\admin\Desktop\wap\static\node_modules\dicer\lib\Dicer.js:62:28
at nextTickCallbackWith0Args (node.js:420:9)
at process._tickDomainCallback (node.js:390:13)
Server
var upload = multer();
router.post('/foo', upload.single('file'), function (req, res, next) {
console.log('foo');
});
client:
ClientRequest {
domain: null,
_events:
{ response: { [Function: g] listener: [Function] },
socket: { [Function: g] listener: [Function] } },
_eventsCount: 2,
_maxListeners: undefined,
output:
[ 'POST /foo HTTP/1.1\r\nContent-Type: multipart/form-data; boundary=-----np0.6452500836458057\r\nContent-Length: 286\r\nHost: localhost:8009\
r\nConnection: close\r\n\r\n-------np0.6452500836458057\r\n',
'Content-Disposition: form-data; name="to"\r\n',
'\r\n',
'/data/static/admin/160601index/html/哈哈.html\r\n',
'-------np0.6452500836458057\r\n',
'Content-Disposition: form-data; name="file"; filename="/html/哈哈.html"\r\n',
'\r\n',
,
'\r\n',
'-------np0.6452500836458057--\r\n' ],
outputEncodings:
[ undefined,
undefined,
undefined,
undefined,
undefined,
undefined,
undefined,
undefined,
undefined,
undefined ],
outputCallbacks:
[ undefined,
undefined,
undefined,
undefined,
undefined,
undefined,
undefined,
undefined,
undefined,
undefined ],
outputSize: 462,
writable: true,
_last: true,
chunkedEncoding: false,
shouldKeepAlive: false,
useChunkedEncodingByDefault: true,
sendDate: false,
_removedHeader: { 'content-length': false },
_contentLength: null,
_hasBody: true,
_trailer: '',
finished: false,
_headerSent: true,
socket: null,
connection: null,
_header: 'POST /foo HTTP/1.1\r\nContent-Type: multipart/form-data; boundary=-----np0.6452500836458057\r\nContent-Length: 286\r\nHost: localhost
:8009\r\nConnection: close\r\n\r\n',
_headers:
{ 'content-type': 'multipart/form-data; boundary=-----np0.6452500836458057',
'content-length': 286,
host: 'localhost:8009' },
_headerNames:
{ 'content-type': 'Content-Type',
'content-length': 'Content-Length',
host: 'Host' },
_onPendingData: null,
agent:
Agent {
domain: null,
_events: { free: [Function] },
_eventsCount: 1,
_maxListeners: undefined,
defaultPort: 80,
protocol: 'http:',
options: { path: null },
requests: {},
sockets: { 'localhost:8009:': [Object] },
freeSockets: {},
keepAliveMsecs: 1000,
keepAlive: false,
maxSockets: Infinity,
maxFreeSockets: 256 },
socketPath: undefined,
method: 'POST',
path: 'foo' }
console
events.js:141
throw er; // Unhandled 'error' event
^Error: socket hang up
at createHangUpError (_http_client.js:200:15)
at Socket.socketOnEnd (_http_client.js:292:23)
at emitNone (events.js:72:20)
at Socket.emit (events.js:166:7)
at endReadableNT (_stream_readable.js:913:12)
at nextTickCallbackWith2Args (node.js:442:9)
at process._tickCallback (node.js:356:17)
It's very hard to understand exactly what's going on from your post, but it seems like the connection between the server and the client got interrupted somehow.
Hence the Error: socket hang up on the client, and Error: Unexpected end of multipart data on the server.
Can you provide any more information?
I have fixed it.
Because the Chinese file name, use encodeURIComponent
Any idea in which minimum version of multer, this issue was solved.
Actually issue was coming due to chinese characters in uploading file
@soakit How did you made the chinese file name to avoid using the encodeURIComponent ?
example:
const fileName = encodeURIComponent ('/文件夹/例子.js'); // means /folder/example.js
@mrmedina87
Thanks!
Using ascii file name, still getting the same error. Hmm... using with nestjs + serverless.
Most helpful comment
Using ascii file name, still getting the same error. Hmm... using with nestjs + serverless.