Y
Y
yazux2017-09-20 11:47:24
JavaScript
yazux, 2017-09-20 11:47:24

How to properly process a request to node.js using multiparty?

For educational purposes, I decided to write an image compressor. I was not familiar with node.js before.
Link to the code on github I
upload images using multiparty.
I ran into a problem: when processing a request, the node falls out with an error:

Error form: Error: stream ended unexpectedly
    at Form.<anonymous> (/projects/node/fileupload/node_modules/multiparty/index.js:754:24)
    at emitNone (events.js:91:20)
    at Form.emit (events.js:185:7)
    at finishMaybe (_stream_writable.js:515:14)
    at endWritable (_stream_writable.js:525:3)
    at Form.Writable.end (_stream_writable.js:490:5)
    at IncomingMessage.onend (_stream_readable.js:511:10)
    at IncomingMessage.g (events.js:291:16)
    at emitNone (events.js:91:20)
    at IncomingMessage.emit (events.js:185:7)
    at endReadableNT (_stream_readable.js:974:12)
    at _combinedTickCallback (internal/process/next_tick.js:74:11)
    at process._tickCallback (internal/process/next_tick.js:98:9)

The image is uploaded to the server, but the request does not go further, everything falls on line 104 of the app.js file.
In addition, before sending the image, the browser sends an OPTION request to the server, the node gives an error about the absence of the boundary part in the content-type header, I wrote it manually in headlines, such a crutch will not let you sleep at night, I myself did not find information about this situation.
Tell me how to solve these 2 problems, unfortunately there are no acquaintances who know the node.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
Y
yazux, 2017-09-23
@yazux

Solved the problem.
Used express-fileupload( example ) instead multipartyof and set in ajax request contentType: falseinstead of contentType: multipart/form-data.

V
Vladimir Skibin, 2017-09-20
@megafax

Try using busboy instead of multiparty. Also check the application for CORS headers if an OPTION request is sent

S
shelomanovd, 2017-09-21
@shelomanovd

the easiest option. Bodyparser and pull out chunks from the body. Push to the array and get it later. All picture is

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question